From: Dennis Chen <dennis.chen-5wv7dgnIgG8@public.gmane.org>
To: Eric Auger <eric.auger-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
Cc: jason-NLaQJdtUoK4Be96aLqz0jA@public.gmane.org,
kvm-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
marc.zyngier-5wv7dgnIgG8@public.gmane.org,
andre.przywara-5wv7dgnIgG8@public.gmane.org,
will.deacon-5wv7dgnIgG8@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org,
kvmarm-FPEHb7Xf0XXUo1n7N8X6UoWGPAHP3yOg@public.gmane.org,
robert.richter-M3mlKVOIwJVv6pq1l3V1OdBPR1lH4CV8@public.gmane.org,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
pbonzini-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org,
tglx-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org,
nd-5wv7dgnIgG8@public.gmane.org,
Manish.Jaggi-M3mlKVOIwJVv6pq1l3V1OdBPR1lH4CV8@public.gmane.org,
christoffer.dall-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org,
eric.auger.pro-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Subject: Re: [PATCH v11 4/8] iommu/msi-iommu: initialization
Date: Wed, 20 Jul 2016 19:43:38 +0800 [thread overview]
Message-ID: <20160720114337.GB1915@arm.com> (raw)
In-Reply-To: <1468932911-23062-5-git-send-email-eric.auger-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
Hi Eric,
Some small questions/comments below:
On Tue, Jul 19, 2016 at 12:55:07PM +0000, Eric Auger wrote:
> iommu_get/put_msi_cookie allocates/frees the resource used to store
> and ref count the MSI doorbell mappings. iommu_msi_set_aperture
> initializes the iova domain used for MSI IOVA allocation and sets the
> iommu domain's msi geometry.
>
> The implementation relies on dma-iommu API and iova API.
>
> New msi functions are fully implemented if CONFIG_IOMMU_MSI is set.
>
> Signed-off-by: Eric Auger <eric.auger-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
>
> ---
> v10:
> - split error management in iommu_msi_set_aperture
>
> v9:
> - remove is_aperture_set and use iommu_domain_msi_aperture_valid helper
> instead
> - set iommu domain's msi geometry
>
> v8:
> - new design where msi-iommu relies on dma-iommu
> - remove the iommu_domain * from the doorbell_mapping struct
> - added is_aperture_set
>
> v7:
> - fix locking
> - add iova_cache_get/put
> - static inline functions when CONFIG_IOMMU_DMA_RESERVED is not set
> - introduce struct reserved_iova_domain to encapsulate prot info &
> add prot parameter in alloc_reserved_iova_domain
>
> v5 -> v6:
> - use spin lock instead of mutex
>
> v3 -> v4:
> - formerly in "iommu/arm-smmu: implement alloc/free_reserved_iova_domain" &
> "iommu: add alloc/free_reserved_iova_domain"
>
> v2 -> v3:
> - remove iommu_alloc_reserved_iova_domain & iommu_free_reserved_iova_domain
> static implementation in case CONFIG_IOMMU_API is not set
>
> v1 -> v2:
> - moved from vfio API to IOMMU API
> ---
> drivers/iommu/Kconfig | 7 ++++
> drivers/iommu/Makefile | 1 +
> drivers/iommu/msi-iommu.c | 100 ++++++++++++++++++++++++++++++++++++++++++++++
> include/linux/msi-iommu.h | 65 ++++++++++++++++++++++++++++++
> 4 files changed, 173 insertions(+)
> create mode 100644 drivers/iommu/msi-iommu.c
> create mode 100644 include/linux/msi-iommu.h
>
> diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig
> index ad08603..5ea1610 100644
> --- a/drivers/iommu/Kconfig
> +++ b/drivers/iommu/Kconfig
> @@ -74,6 +74,11 @@ config IOMMU_DMA
> select IOMMU_IOVA
> select NEED_SG_DMA_LENGTH
>
> +# IOMMU MSI mapping
> +config IOMMU_MSI
> + bool
> + select IOMMU_DMA
> +
> config FSL_PAMU
> bool "Freescale IOMMU support"
> depends on PPC_E500MC || (COMPILE_TEST && PPC)
> @@ -296,6 +301,7 @@ config SPAPR_TCE_IOMMU
> config ARM_SMMU
> bool "ARM Ltd. System MMU (SMMU) Support"
> depends on (ARM64 || ARM) && MMU
> + select IOMMU_MSI
> select IOMMU_API
> select IOMMU_IO_PGTABLE_LPAE
> select ARM_DMA_USE_IOMMU if ARM
> @@ -309,6 +315,7 @@ config ARM_SMMU
> config ARM_SMMU_V3
> bool "ARM Ltd. System MMU Version 3 (SMMUv3) Support"
> depends on ARM64 && PCI
> + select IOMMU_MSI
> select IOMMU_API
> select IOMMU_IO_PGTABLE_LPAE
> select GENERIC_MSI_IRQ_DOMAIN
> diff --git a/drivers/iommu/Makefile b/drivers/iommu/Makefile
> index c6edb31..a381e66 100644
> --- a/drivers/iommu/Makefile
> +++ b/drivers/iommu/Makefile
> @@ -2,6 +2,7 @@ obj-$(CONFIG_IOMMU_API) += iommu.o
> obj-$(CONFIG_IOMMU_API) += iommu-traces.o
> obj-$(CONFIG_IOMMU_API) += iommu-sysfs.o
> obj-$(CONFIG_IOMMU_DMA) += dma-iommu.o
> +obj-$(CONFIG_IOMMU_MSI) += msi-iommu.o
> obj-$(CONFIG_IOMMU_IO_PGTABLE) += io-pgtable.o
> obj-$(CONFIG_IOMMU_IO_PGTABLE_ARMV7S) += io-pgtable-arm-v7s.o
> obj-$(CONFIG_IOMMU_IO_PGTABLE_LPAE) += io-pgtable-arm.o
> diff --git a/drivers/iommu/msi-iommu.c b/drivers/iommu/msi-iommu.c
> new file mode 100644
> index 0000000..de02ede
> --- /dev/null
> +++ b/drivers/iommu/msi-iommu.c
> @@ -0,0 +1,100 @@
> +/*
> + * Reserved IOVA Management
> + *
> + * Copyright (c) 2015 Linaro Ltd.
> + * www.linaro.org
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + */
> +
> +#include <linux/iommu.h>
> +#include <linux/dma-iommu.h>
> +#include <linux/msi-iommu.h>
> +#include <linux/spinlock.h>
> +#include <linux/iova.h>
> +
> +struct doorbell_mapping {
> + struct kref kref;
> + struct list_head next;
> + phys_addr_t addr;
> + dma_addr_t iova;
> + size_t size;
> +};
> +
> +struct doorbell_mapping_info {
> + struct list_head list; /* list of doorbell mapping entries */
> + spinlock_t lock;
> +};
> +
> +int iommu_get_msi_cookie(struct iommu_domain *domain)
> +{
> + struct doorbell_mapping_info *dmi;
> + int ret;
> +
> + if (domain->msi_cookie || domain->iova_cookie)
> + return -EINVAL;
> +
> + ret = iommu_get_dma_cookie(domain);
> + if (ret)
> + return ret;
> +
> + dmi = kzalloc(sizeof(*dmi), GFP_KERNEL);
if dmi == NULL here,
> +
> + INIT_LIST_HEAD(&dmi->list);
> + spin_lock_init(&dmi->lock);
will the above 2-line codes triger kernel NULL pointer dereference panic message?
if so why don't we check dmi immediately after the kzalloc call like this:
dmi = kzalloc(sizeof(*dmi), GFP_KERNEL);
domain->msi_cookie = dmi;
if (!dmi)
return -ENOMEM;
> + iova_cache_get();
return iova_cache_get();
> +
> + domain->msi_cookie = dmi;
> +
> + return dmi ? 0 : -ENOMEM;
> +}
> +EXPORT_SYMBOL(iommu_get_msi_cookie);
> +
> +void iommu_put_msi_cookie(struct iommu_domain *domain)
> +{
> + struct doorbell_mapping_info *dmi = domain->msi_cookie;
> +
> + if (!dmi)
> + return;
> +
> + domain->msi_cookie = NULL;
> +
> + WARN_ON(!list_empty(&dmi->list));
> +
> + kfree(dmi);
> + iommu_put_dma_cookie(domain);
> + iova_cache_put();
> +}
> +EXPORT_SYMBOL(iommu_put_msi_cookie);
> +
> +int iommu_msi_set_aperture(struct iommu_domain *domain,
> + dma_addr_t start, dma_addr_t end)
> +{
> + struct doorbell_mapping_info *dmi = domain->msi_cookie;
> + int ret;
> +
> + if (!dmi)
> + return -ENODEV;
> +
> + if (iommu_domain_msi_aperture_valid(domain))
> + return -EINVAL;
> +
> + ret = iommu_dma_init_domain(domain, start, end - start + 1);
> +
> + if (!ret) {
> + domain->msi_geometry.aperture_start = start;
> + domain->msi_geometry.aperture_end = end;
> + }
> +
> + return ret;
> +}
> +EXPORT_SYMBOL_GPL(iommu_msi_set_aperture);
> +
> diff --git a/include/linux/msi-iommu.h b/include/linux/msi-iommu.h
> new file mode 100644
> index 0000000..392aa6f
> --- /dev/null
> +++ b/include/linux/msi-iommu.h
> @@ -0,0 +1,65 @@
> +/*
> + * Copyright (c) 2015 Linaro Ltd.
> + * www.linaro.org
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + */
> +#ifndef __MSI_IOMMU_H
> +#define __MSI_IOMMU_H
> +
> +#include <linux/types.h>
> +#include <linux/kernel.h>
> +
> +struct iommu_domain;
> +
> +#ifdef CONFIG_IOMMU_MSI
> +
> +/**
> + * iommu_get_msi_cookie - Acquire MSI mapping resources for a domain
> + * @domain: IOMMU domain to prepare for MSI mapping
> + *
> + * IOMMU drivers which require MSI mapping should normally call this
> + * from their domain_alloc callback when domain->type ==
> + * IOMMU_DOMAIN_UNMANAGED.
> + */
> +int iommu_get_msi_cookie(struct iommu_domain *domain);
> +
> +/**
> + * iommu_put_msi_cookie - Release a domain's MSI mapping resources
> + * @domain: IOMMU domain previously prepared by iommu_get_msi_cookie()
> + *
> + * IOMMU drivers requesting MSI mapping should normally call this from
> + * their domain_free callback.
> + */
> +void iommu_put_msi_cookie(struct iommu_domain *domain);
> +
> +/**
> + * iommu_msi_set_aperture: allocate the msi iova domain
> + * according to the specified start/end IOVAs
> + *
> + * @domain: iommu domain handle
> + * @start: MSI iova start address
> + * @end: MSI iova end address
> + */
> +int iommu_msi_set_aperture(struct iommu_domain *domain,
> + dma_addr_t start, dma_addr_t end);
> +
> +#else
> +
> +static inline int
> +iommu_msi_set_aperture(struct iommu_domain *domain,
> + dma_addr_t start, dma_addr_t end)
> +{
> + return -ENOENT;
> +}
> +
> +#endif /* CONFIG_IOMMU_MSI */
> +#endif /* __MSI_IOMMU_H */
> --
> 1.9.1
>
> _______________________________________________
> kvmarm mailing list
> kvmarm-FPEHb7Xf0XXUo1n7N8X6UoWGPAHP3yOg@public.gmane.org
> https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
>
WARNING: multiple messages have this Message-ID (diff)
From: dennis.chen@arm.com (Dennis Chen)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v11 4/8] iommu/msi-iommu: initialization
Date: Wed, 20 Jul 2016 19:43:38 +0800 [thread overview]
Message-ID: <20160720114337.GB1915@arm.com> (raw)
In-Reply-To: <1468932911-23062-5-git-send-email-eric.auger@redhat.com>
Hi Eric,
Some small questions/comments below:
On Tue, Jul 19, 2016 at 12:55:07PM +0000, Eric Auger wrote:
> iommu_get/put_msi_cookie allocates/frees the resource used to store
> and ref count the MSI doorbell mappings. iommu_msi_set_aperture
> initializes the iova domain used for MSI IOVA allocation and sets the
> iommu domain's msi geometry.
>
> The implementation relies on dma-iommu API and iova API.
>
> New msi functions are fully implemented if CONFIG_IOMMU_MSI is set.
>
> Signed-off-by: Eric Auger <eric.auger@redhat.com>
>
> ---
> v10:
> - split error management in iommu_msi_set_aperture
>
> v9:
> - remove is_aperture_set and use iommu_domain_msi_aperture_valid helper
> instead
> - set iommu domain's msi geometry
>
> v8:
> - new design where msi-iommu relies on dma-iommu
> - remove the iommu_domain * from the doorbell_mapping struct
> - added is_aperture_set
>
> v7:
> - fix locking
> - add iova_cache_get/put
> - static inline functions when CONFIG_IOMMU_DMA_RESERVED is not set
> - introduce struct reserved_iova_domain to encapsulate prot info &
> add prot parameter in alloc_reserved_iova_domain
>
> v5 -> v6:
> - use spin lock instead of mutex
>
> v3 -> v4:
> - formerly in "iommu/arm-smmu: implement alloc/free_reserved_iova_domain" &
> "iommu: add alloc/free_reserved_iova_domain"
>
> v2 -> v3:
> - remove iommu_alloc_reserved_iova_domain & iommu_free_reserved_iova_domain
> static implementation in case CONFIG_IOMMU_API is not set
>
> v1 -> v2:
> - moved from vfio API to IOMMU API
> ---
> drivers/iommu/Kconfig | 7 ++++
> drivers/iommu/Makefile | 1 +
> drivers/iommu/msi-iommu.c | 100 ++++++++++++++++++++++++++++++++++++++++++++++
> include/linux/msi-iommu.h | 65 ++++++++++++++++++++++++++++++
> 4 files changed, 173 insertions(+)
> create mode 100644 drivers/iommu/msi-iommu.c
> create mode 100644 include/linux/msi-iommu.h
>
> diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig
> index ad08603..5ea1610 100644
> --- a/drivers/iommu/Kconfig
> +++ b/drivers/iommu/Kconfig
> @@ -74,6 +74,11 @@ config IOMMU_DMA
> select IOMMU_IOVA
> select NEED_SG_DMA_LENGTH
>
> +# IOMMU MSI mapping
> +config IOMMU_MSI
> + bool
> + select IOMMU_DMA
> +
> config FSL_PAMU
> bool "Freescale IOMMU support"
> depends on PPC_E500MC || (COMPILE_TEST && PPC)
> @@ -296,6 +301,7 @@ config SPAPR_TCE_IOMMU
> config ARM_SMMU
> bool "ARM Ltd. System MMU (SMMU) Support"
> depends on (ARM64 || ARM) && MMU
> + select IOMMU_MSI
> select IOMMU_API
> select IOMMU_IO_PGTABLE_LPAE
> select ARM_DMA_USE_IOMMU if ARM
> @@ -309,6 +315,7 @@ config ARM_SMMU
> config ARM_SMMU_V3
> bool "ARM Ltd. System MMU Version 3 (SMMUv3) Support"
> depends on ARM64 && PCI
> + select IOMMU_MSI
> select IOMMU_API
> select IOMMU_IO_PGTABLE_LPAE
> select GENERIC_MSI_IRQ_DOMAIN
> diff --git a/drivers/iommu/Makefile b/drivers/iommu/Makefile
> index c6edb31..a381e66 100644
> --- a/drivers/iommu/Makefile
> +++ b/drivers/iommu/Makefile
> @@ -2,6 +2,7 @@ obj-$(CONFIG_IOMMU_API) += iommu.o
> obj-$(CONFIG_IOMMU_API) += iommu-traces.o
> obj-$(CONFIG_IOMMU_API) += iommu-sysfs.o
> obj-$(CONFIG_IOMMU_DMA) += dma-iommu.o
> +obj-$(CONFIG_IOMMU_MSI) += msi-iommu.o
> obj-$(CONFIG_IOMMU_IO_PGTABLE) += io-pgtable.o
> obj-$(CONFIG_IOMMU_IO_PGTABLE_ARMV7S) += io-pgtable-arm-v7s.o
> obj-$(CONFIG_IOMMU_IO_PGTABLE_LPAE) += io-pgtable-arm.o
> diff --git a/drivers/iommu/msi-iommu.c b/drivers/iommu/msi-iommu.c
> new file mode 100644
> index 0000000..de02ede
> --- /dev/null
> +++ b/drivers/iommu/msi-iommu.c
> @@ -0,0 +1,100 @@
> +/*
> + * Reserved IOVA Management
> + *
> + * Copyright (c) 2015 Linaro Ltd.
> + * www.linaro.org
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + */
> +
> +#include <linux/iommu.h>
> +#include <linux/dma-iommu.h>
> +#include <linux/msi-iommu.h>
> +#include <linux/spinlock.h>
> +#include <linux/iova.h>
> +
> +struct doorbell_mapping {
> + struct kref kref;
> + struct list_head next;
> + phys_addr_t addr;
> + dma_addr_t iova;
> + size_t size;
> +};
> +
> +struct doorbell_mapping_info {
> + struct list_head list; /* list of doorbell mapping entries */
> + spinlock_t lock;
> +};
> +
> +int iommu_get_msi_cookie(struct iommu_domain *domain)
> +{
> + struct doorbell_mapping_info *dmi;
> + int ret;
> +
> + if (domain->msi_cookie || domain->iova_cookie)
> + return -EINVAL;
> +
> + ret = iommu_get_dma_cookie(domain);
> + if (ret)
> + return ret;
> +
> + dmi = kzalloc(sizeof(*dmi), GFP_KERNEL);
if dmi == NULL here,
> +
> + INIT_LIST_HEAD(&dmi->list);
> + spin_lock_init(&dmi->lock);
will the above 2-line codes triger kernel NULL pointer dereference panic message?
if so why don't we check dmi immediately after the kzalloc call like this:
dmi = kzalloc(sizeof(*dmi), GFP_KERNEL);
domain->msi_cookie = dmi;
if (!dmi)
return -ENOMEM;
> + iova_cache_get();
return iova_cache_get();
> +
> + domain->msi_cookie = dmi;
> +
> + return dmi ? 0 : -ENOMEM;
> +}
> +EXPORT_SYMBOL(iommu_get_msi_cookie);
> +
> +void iommu_put_msi_cookie(struct iommu_domain *domain)
> +{
> + struct doorbell_mapping_info *dmi = domain->msi_cookie;
> +
> + if (!dmi)
> + return;
> +
> + domain->msi_cookie = NULL;
> +
> + WARN_ON(!list_empty(&dmi->list));
> +
> + kfree(dmi);
> + iommu_put_dma_cookie(domain);
> + iova_cache_put();
> +}
> +EXPORT_SYMBOL(iommu_put_msi_cookie);
> +
> +int iommu_msi_set_aperture(struct iommu_domain *domain,
> + dma_addr_t start, dma_addr_t end)
> +{
> + struct doorbell_mapping_info *dmi = domain->msi_cookie;
> + int ret;
> +
> + if (!dmi)
> + return -ENODEV;
> +
> + if (iommu_domain_msi_aperture_valid(domain))
> + return -EINVAL;
> +
> + ret = iommu_dma_init_domain(domain, start, end - start + 1);
> +
> + if (!ret) {
> + domain->msi_geometry.aperture_start = start;
> + domain->msi_geometry.aperture_end = end;
> + }
> +
> + return ret;
> +}
> +EXPORT_SYMBOL_GPL(iommu_msi_set_aperture);
> +
> diff --git a/include/linux/msi-iommu.h b/include/linux/msi-iommu.h
> new file mode 100644
> index 0000000..392aa6f
> --- /dev/null
> +++ b/include/linux/msi-iommu.h
> @@ -0,0 +1,65 @@
> +/*
> + * Copyright (c) 2015 Linaro Ltd.
> + * www.linaro.org
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + */
> +#ifndef __MSI_IOMMU_H
> +#define __MSI_IOMMU_H
> +
> +#include <linux/types.h>
> +#include <linux/kernel.h>
> +
> +struct iommu_domain;
> +
> +#ifdef CONFIG_IOMMU_MSI
> +
> +/**
> + * iommu_get_msi_cookie - Acquire MSI mapping resources for a domain
> + * @domain: IOMMU domain to prepare for MSI mapping
> + *
> + * IOMMU drivers which require MSI mapping should normally call this
> + * from their domain_alloc callback when domain->type ==
> + * IOMMU_DOMAIN_UNMANAGED.
> + */
> +int iommu_get_msi_cookie(struct iommu_domain *domain);
> +
> +/**
> + * iommu_put_msi_cookie - Release a domain's MSI mapping resources
> + * @domain: IOMMU domain previously prepared by iommu_get_msi_cookie()
> + *
> + * IOMMU drivers requesting MSI mapping should normally call this from
> + * their domain_free callback.
> + */
> +void iommu_put_msi_cookie(struct iommu_domain *domain);
> +
> +/**
> + * iommu_msi_set_aperture: allocate the msi iova domain
> + * according to the specified start/end IOVAs
> + *
> + * @domain: iommu domain handle
> + * @start: MSI iova start address
> + * @end: MSI iova end address
> + */
> +int iommu_msi_set_aperture(struct iommu_domain *domain,
> + dma_addr_t start, dma_addr_t end);
> +
> +#else
> +
> +static inline int
> +iommu_msi_set_aperture(struct iommu_domain *domain,
> + dma_addr_t start, dma_addr_t end)
> +{
> + return -ENOENT;
> +}
> +
> +#endif /* CONFIG_IOMMU_MSI */
> +#endif /* __MSI_IOMMU_H */
> --
> 1.9.1
>
> _______________________________________________
> kvmarm mailing list
> kvmarm at lists.cs.columbia.edu
> https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
>
WARNING: multiple messages have this Message-ID (diff)
From: Dennis Chen <dennis.chen@arm.com>
To: Eric Auger <eric.auger@redhat.com>
Cc: <eric.auger.pro@gmail.com>, <marc.zyngier@arm.com>,
<christoffer.dall@linaro.org>, <andre.przywara@arm.com>,
<robin.murphy@arm.com>, <alex.williamson@redhat.com>,
<will.deacon@arm.com>, <joro@8bytes.org>, <tglx@linutronix.de>,
<jason@lakedaemon.net>, <linux-arm-kernel@lists.infradead.org>,
<kvm@vger.kernel.org>, <Manish.Jaggi@caviumnetworks.com>,
<linux-kernel@vger.kernel.org>,
<iommu@lists.linux-foundation.org>, <pbonzini@redhat.com>,
<kvmarm@lists.cs.columbia.edu>,
<robert.richter@caviumnetworks.com>, <nd@arm.com>
Subject: Re: [PATCH v11 4/8] iommu/msi-iommu: initialization
Date: Wed, 20 Jul 2016 19:43:38 +0800 [thread overview]
Message-ID: <20160720114337.GB1915@arm.com> (raw)
In-Reply-To: <1468932911-23062-5-git-send-email-eric.auger@redhat.com>
Hi Eric,
Some small questions/comments below:
On Tue, Jul 19, 2016 at 12:55:07PM +0000, Eric Auger wrote:
> iommu_get/put_msi_cookie allocates/frees the resource used to store
> and ref count the MSI doorbell mappings. iommu_msi_set_aperture
> initializes the iova domain used for MSI IOVA allocation and sets the
> iommu domain's msi geometry.
>
> The implementation relies on dma-iommu API and iova API.
>
> New msi functions are fully implemented if CONFIG_IOMMU_MSI is set.
>
> Signed-off-by: Eric Auger <eric.auger@redhat.com>
>
> ---
> v10:
> - split error management in iommu_msi_set_aperture
>
> v9:
> - remove is_aperture_set and use iommu_domain_msi_aperture_valid helper
> instead
> - set iommu domain's msi geometry
>
> v8:
> - new design where msi-iommu relies on dma-iommu
> - remove the iommu_domain * from the doorbell_mapping struct
> - added is_aperture_set
>
> v7:
> - fix locking
> - add iova_cache_get/put
> - static inline functions when CONFIG_IOMMU_DMA_RESERVED is not set
> - introduce struct reserved_iova_domain to encapsulate prot info &
> add prot parameter in alloc_reserved_iova_domain
>
> v5 -> v6:
> - use spin lock instead of mutex
>
> v3 -> v4:
> - formerly in "iommu/arm-smmu: implement alloc/free_reserved_iova_domain" &
> "iommu: add alloc/free_reserved_iova_domain"
>
> v2 -> v3:
> - remove iommu_alloc_reserved_iova_domain & iommu_free_reserved_iova_domain
> static implementation in case CONFIG_IOMMU_API is not set
>
> v1 -> v2:
> - moved from vfio API to IOMMU API
> ---
> drivers/iommu/Kconfig | 7 ++++
> drivers/iommu/Makefile | 1 +
> drivers/iommu/msi-iommu.c | 100 ++++++++++++++++++++++++++++++++++++++++++++++
> include/linux/msi-iommu.h | 65 ++++++++++++++++++++++++++++++
> 4 files changed, 173 insertions(+)
> create mode 100644 drivers/iommu/msi-iommu.c
> create mode 100644 include/linux/msi-iommu.h
>
> diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig
> index ad08603..5ea1610 100644
> --- a/drivers/iommu/Kconfig
> +++ b/drivers/iommu/Kconfig
> @@ -74,6 +74,11 @@ config IOMMU_DMA
> select IOMMU_IOVA
> select NEED_SG_DMA_LENGTH
>
> +# IOMMU MSI mapping
> +config IOMMU_MSI
> + bool
> + select IOMMU_DMA
> +
> config FSL_PAMU
> bool "Freescale IOMMU support"
> depends on PPC_E500MC || (COMPILE_TEST && PPC)
> @@ -296,6 +301,7 @@ config SPAPR_TCE_IOMMU
> config ARM_SMMU
> bool "ARM Ltd. System MMU (SMMU) Support"
> depends on (ARM64 || ARM) && MMU
> + select IOMMU_MSI
> select IOMMU_API
> select IOMMU_IO_PGTABLE_LPAE
> select ARM_DMA_USE_IOMMU if ARM
> @@ -309,6 +315,7 @@ config ARM_SMMU
> config ARM_SMMU_V3
> bool "ARM Ltd. System MMU Version 3 (SMMUv3) Support"
> depends on ARM64 && PCI
> + select IOMMU_MSI
> select IOMMU_API
> select IOMMU_IO_PGTABLE_LPAE
> select GENERIC_MSI_IRQ_DOMAIN
> diff --git a/drivers/iommu/Makefile b/drivers/iommu/Makefile
> index c6edb31..a381e66 100644
> --- a/drivers/iommu/Makefile
> +++ b/drivers/iommu/Makefile
> @@ -2,6 +2,7 @@ obj-$(CONFIG_IOMMU_API) += iommu.o
> obj-$(CONFIG_IOMMU_API) += iommu-traces.o
> obj-$(CONFIG_IOMMU_API) += iommu-sysfs.o
> obj-$(CONFIG_IOMMU_DMA) += dma-iommu.o
> +obj-$(CONFIG_IOMMU_MSI) += msi-iommu.o
> obj-$(CONFIG_IOMMU_IO_PGTABLE) += io-pgtable.o
> obj-$(CONFIG_IOMMU_IO_PGTABLE_ARMV7S) += io-pgtable-arm-v7s.o
> obj-$(CONFIG_IOMMU_IO_PGTABLE_LPAE) += io-pgtable-arm.o
> diff --git a/drivers/iommu/msi-iommu.c b/drivers/iommu/msi-iommu.c
> new file mode 100644
> index 0000000..de02ede
> --- /dev/null
> +++ b/drivers/iommu/msi-iommu.c
> @@ -0,0 +1,100 @@
> +/*
> + * Reserved IOVA Management
> + *
> + * Copyright (c) 2015 Linaro Ltd.
> + * www.linaro.org
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + */
> +
> +#include <linux/iommu.h>
> +#include <linux/dma-iommu.h>
> +#include <linux/msi-iommu.h>
> +#include <linux/spinlock.h>
> +#include <linux/iova.h>
> +
> +struct doorbell_mapping {
> + struct kref kref;
> + struct list_head next;
> + phys_addr_t addr;
> + dma_addr_t iova;
> + size_t size;
> +};
> +
> +struct doorbell_mapping_info {
> + struct list_head list; /* list of doorbell mapping entries */
> + spinlock_t lock;
> +};
> +
> +int iommu_get_msi_cookie(struct iommu_domain *domain)
> +{
> + struct doorbell_mapping_info *dmi;
> + int ret;
> +
> + if (domain->msi_cookie || domain->iova_cookie)
> + return -EINVAL;
> +
> + ret = iommu_get_dma_cookie(domain);
> + if (ret)
> + return ret;
> +
> + dmi = kzalloc(sizeof(*dmi), GFP_KERNEL);
if dmi == NULL here,
> +
> + INIT_LIST_HEAD(&dmi->list);
> + spin_lock_init(&dmi->lock);
will the above 2-line codes triger kernel NULL pointer dereference panic message?
if so why don't we check dmi immediately after the kzalloc call like this:
dmi = kzalloc(sizeof(*dmi), GFP_KERNEL);
domain->msi_cookie = dmi;
if (!dmi)
return -ENOMEM;
> + iova_cache_get();
return iova_cache_get();
> +
> + domain->msi_cookie = dmi;
> +
> + return dmi ? 0 : -ENOMEM;
> +}
> +EXPORT_SYMBOL(iommu_get_msi_cookie);
> +
> +void iommu_put_msi_cookie(struct iommu_domain *domain)
> +{
> + struct doorbell_mapping_info *dmi = domain->msi_cookie;
> +
> + if (!dmi)
> + return;
> +
> + domain->msi_cookie = NULL;
> +
> + WARN_ON(!list_empty(&dmi->list));
> +
> + kfree(dmi);
> + iommu_put_dma_cookie(domain);
> + iova_cache_put();
> +}
> +EXPORT_SYMBOL(iommu_put_msi_cookie);
> +
> +int iommu_msi_set_aperture(struct iommu_domain *domain,
> + dma_addr_t start, dma_addr_t end)
> +{
> + struct doorbell_mapping_info *dmi = domain->msi_cookie;
> + int ret;
> +
> + if (!dmi)
> + return -ENODEV;
> +
> + if (iommu_domain_msi_aperture_valid(domain))
> + return -EINVAL;
> +
> + ret = iommu_dma_init_domain(domain, start, end - start + 1);
> +
> + if (!ret) {
> + domain->msi_geometry.aperture_start = start;
> + domain->msi_geometry.aperture_end = end;
> + }
> +
> + return ret;
> +}
> +EXPORT_SYMBOL_GPL(iommu_msi_set_aperture);
> +
> diff --git a/include/linux/msi-iommu.h b/include/linux/msi-iommu.h
> new file mode 100644
> index 0000000..392aa6f
> --- /dev/null
> +++ b/include/linux/msi-iommu.h
> @@ -0,0 +1,65 @@
> +/*
> + * Copyright (c) 2015 Linaro Ltd.
> + * www.linaro.org
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + */
> +#ifndef __MSI_IOMMU_H
> +#define __MSI_IOMMU_H
> +
> +#include <linux/types.h>
> +#include <linux/kernel.h>
> +
> +struct iommu_domain;
> +
> +#ifdef CONFIG_IOMMU_MSI
> +
> +/**
> + * iommu_get_msi_cookie - Acquire MSI mapping resources for a domain
> + * @domain: IOMMU domain to prepare for MSI mapping
> + *
> + * IOMMU drivers which require MSI mapping should normally call this
> + * from their domain_alloc callback when domain->type ==
> + * IOMMU_DOMAIN_UNMANAGED.
> + */
> +int iommu_get_msi_cookie(struct iommu_domain *domain);
> +
> +/**
> + * iommu_put_msi_cookie - Release a domain's MSI mapping resources
> + * @domain: IOMMU domain previously prepared by iommu_get_msi_cookie()
> + *
> + * IOMMU drivers requesting MSI mapping should normally call this from
> + * their domain_free callback.
> + */
> +void iommu_put_msi_cookie(struct iommu_domain *domain);
> +
> +/**
> + * iommu_msi_set_aperture: allocate the msi iova domain
> + * according to the specified start/end IOVAs
> + *
> + * @domain: iommu domain handle
> + * @start: MSI iova start address
> + * @end: MSI iova end address
> + */
> +int iommu_msi_set_aperture(struct iommu_domain *domain,
> + dma_addr_t start, dma_addr_t end);
> +
> +#else
> +
> +static inline int
> +iommu_msi_set_aperture(struct iommu_domain *domain,
> + dma_addr_t start, dma_addr_t end)
> +{
> + return -ENOENT;
> +}
> +
> +#endif /* CONFIG_IOMMU_MSI */
> +#endif /* __MSI_IOMMU_H */
> --
> 1.9.1
>
> _______________________________________________
> kvmarm mailing list
> kvmarm@lists.cs.columbia.edu
> https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
>
next prev parent reply other threads:[~2016-07-20 11:43 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-19 12:55 [PATCH v11 0/8] KVM PCIe/MSI passthrough on ARM/ARM64: kernel part 1/3: iommu changes Eric Auger
2016-07-19 12:55 ` Eric Auger
2016-07-19 12:55 ` Eric Auger
[not found] ` <1468932911-23062-1-git-send-email-eric.auger-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-07-19 12:55 ` [PATCH v11 1/8] iommu: Add iommu_domain_msi_geometry and DOMAIN_ATTR_MSI_GEOMETRY Eric Auger
2016-07-19 12:55 ` Eric Auger
2016-07-19 12:55 ` Eric Auger
2016-07-19 12:55 ` [PATCH v11 2/8] iommu/arm-smmu: initialize the msi geometry and advertise iommu-msi support Eric Auger
2016-07-19 12:55 ` Eric Auger
2016-07-19 12:55 ` Eric Auger
2016-07-19 12:55 ` [PATCH v11 3/8] iommu: introduce an msi cookie Eric Auger
2016-07-19 12:55 ` Eric Auger
2016-07-19 12:55 ` Eric Auger
2016-07-19 12:55 ` [PATCH v11 6/8] iommu/msi-iommu: iommu_msi_domain Eric Auger
2016-07-19 12:55 ` Eric Auger
2016-07-19 12:55 ` Eric Auger
2016-07-20 9:56 ` [PATCH v11 0/8] KVM PCIe/MSI passthrough on ARM/ARM64: kernel part 1/3: iommu changes Dennis Chen
2016-07-20 9:56 ` Dennis Chen
2016-07-20 9:56 ` Dennis Chen
2016-07-20 11:03 ` Auger Eric
2016-07-20 11:03 ` Auger Eric
[not found] ` <27715cdb-9f39-7860-465b-e533f4a5c03c-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-07-20 11:52 ` Dennis Chen
2016-07-20 11:52 ` Dennis Chen
2016-07-20 11:52 ` Dennis Chen
2016-07-19 12:55 ` [PATCH v11 4/8] iommu/msi-iommu: initialization Eric Auger
2016-07-19 12:55 ` Eric Auger
2016-07-19 12:55 ` Eric Auger
[not found] ` <1468932911-23062-5-git-send-email-eric.auger-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-07-20 11:43 ` Dennis Chen [this message]
2016-07-20 11:43 ` Dennis Chen
2016-07-20 11:43 ` Dennis Chen
[not found] ` <20160720114337.GB1915-5wv7dgnIgG8@public.gmane.org>
2016-07-27 20:38 ` Auger Eric
2016-07-27 20:38 ` Auger Eric
2016-07-27 20:38 ` Auger Eric
2016-07-19 12:55 ` [PATCH v11 5/8] iommu/msi-iommu: iommu_msi_[get,put]_doorbell_iova Eric Auger
2016-07-19 12:55 ` Eric Auger
2016-07-19 12:55 ` Eric Auger
2016-07-19 12:55 ` [PATCH v11 7/8] iommu/msi-iommu: iommu_msi_msg_pa_to_va Eric Auger
2016-07-19 12:55 ` Eric Auger
2016-07-19 12:55 ` [PATCH v11 8/8] iommu/arm-smmu: get/put the msi cookie Eric Auger
2016-07-19 12:55 ` Eric Auger
2016-07-19 12:55 ` Eric Auger
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=20160720114337.GB1915@arm.com \
--to=dennis.chen-5wv7dgnigg8@public.gmane.org \
--cc=Manish.Jaggi-M3mlKVOIwJVv6pq1l3V1OdBPR1lH4CV8@public.gmane.org \
--cc=andre.przywara-5wv7dgnIgG8@public.gmane.org \
--cc=christoffer.dall-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
--cc=eric.auger-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
--cc=eric.auger.pro-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
--cc=jason-NLaQJdtUoK4Be96aLqz0jA@public.gmane.org \
--cc=kvm-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=kvmarm-FPEHb7Xf0XXUo1n7N8X6UoWGPAHP3yOg@public.gmane.org \
--cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=marc.zyngier-5wv7dgnIgG8@public.gmane.org \
--cc=nd-5wv7dgnIgG8@public.gmane.org \
--cc=pbonzini-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
--cc=robert.richter-M3mlKVOIwJVv6pq1l3V1OdBPR1lH4CV8@public.gmane.org \
--cc=tglx-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org \
--cc=will.deacon-5wv7dgnIgG8@public.gmane.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 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.