From: Alexey Kardashevskiy <aik@ozlabs.ru>
To: Alex Williamson <alex.williamson@redhat.com>
Cc: David Gibson <david@gibson.dropbear.id.au>,
Paul Mackerras <paulus@samba.org>,
linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] vfio powerpc: enabled on powernv platform
Date: Sat, 01 Dec 2012 11:14:40 +1100 [thread overview]
Message-ID: <50B94BF0.4080408@ozlabs.ru> (raw)
In-Reply-To: <1354294088.14547.36.camel@ul30vt.home>
On 01/12/12 03:48, Alex Williamson wrote:
> On Fri, 2012-11-30 at 17:14 +1100, Alexey Kardashevskiy wrote:
>> This patch initializes IOMMU groups based on the IOMMU
>> configuration discovered during the PCI scan on POWERNV
>> (POWER non virtualized) platform. The IOMMU groups are
>> to be used later by VFIO driver (PCI pass through).
>>
>> It also implements an API for mapping/unmapping pages for
>> guest PCI drivers and providing DMA window properties.
>> This API is going to be used later by QEMU-VFIO to handle
>> h_put_tce hypercalls from the KVM guest.
>>
>> Although this driver has been tested only on the POWERNV
>> platform, it should work on any platform which supports
>> TCE tables.
>>
>> To enable VFIO on POWER, enable SPAPR_TCE_IOMMU config
>> option and configure VFIO as required.
>>
>> Cc: David Gibson <david@gibson.dropbear.id.au>
>> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
>> ---
>> arch/powerpc/include/asm/iommu.h | 9 ++
>> arch/powerpc/kernel/iommu.c | 186 ++++++++++++++++++++++++++++++++++
>> arch/powerpc/platforms/powernv/pci.c | 135 ++++++++++++++++++++++++
>> drivers/iommu/Kconfig | 8 ++
>> 4 files changed, 338 insertions(+)
>>
>> diff --git a/arch/powerpc/include/asm/iommu.h b/arch/powerpc/include/asm/iommu.h
>> index cbfe678..5c7087a 100644
>> --- a/arch/powerpc/include/asm/iommu.h
>> +++ b/arch/powerpc/include/asm/iommu.h
>> @@ -76,6 +76,9 @@ struct iommu_table {
>> struct iommu_pool large_pool;
>> struct iommu_pool pools[IOMMU_NR_POOLS];
>> unsigned long *it_map; /* A simple allocation bitmap for now */
>> +#ifdef CONFIG_IOMMU_API
>> + struct iommu_group *it_group;
>> +#endif
>> };
>>
>> struct scatterlist;
>> @@ -147,5 +150,11 @@ static inline void iommu_restore(void)
>> }
>> #endif
>>
>> +extern long iommu_clear_tces(struct iommu_table *tbl, unsigned long entry,
>> + unsigned long pages);
>> +extern long iommu_put_tces(struct iommu_table *tbl, unsigned long entry,
>> + uint64_t tce, enum dma_data_direction direction,
>> + unsigned long pages);
>> +
>> #endif /* __KERNEL__ */
>> #endif /* _ASM_IOMMU_H */
>> diff --git a/arch/powerpc/kernel/iommu.c b/arch/powerpc/kernel/iommu.c
>> index ff5a6ce..0646c50 100644
>> --- a/arch/powerpc/kernel/iommu.c
>> +++ b/arch/powerpc/kernel/iommu.c
>> @@ -44,6 +44,7 @@
>> #include <asm/kdump.h>
>> #include <asm/fadump.h>
>> #include <asm/vio.h>
>> +#include <asm/tce.h>
>>
>> #define DBG(...)
>>
>> @@ -856,3 +857,188 @@ void iommu_free_coherent(struct iommu_table *tbl, size_t size,
>> free_pages((unsigned long)vaddr, get_order(size));
>> }
>> }
>> +
>> +#ifdef CONFIG_IOMMU_API
>> +/*
>> + * SPAPR TCE API
>> + */
>> +
>> +/*
>> + * Returns the number of used IOMMU pages (4K) within
>> + * the same system page (4K or 64K).
>> + * bitmap_weight is not used as it does not support bigendian maps.
>> + */
>> +static int syspage_weight(unsigned long *map, unsigned long entry)
>> +{
>> + int ret = 0, nbits = PAGE_SIZE/IOMMU_PAGE_SIZE;
>> +
>> + /* Aligns TCE entry number to system page boundary */
>> + entry &= PAGE_MASK >> IOMMU_PAGE_SHIFT;
>> +
>> + /* Count used 4K pages */
>> + while (nbits--)
>> + ret += (test_bit(entry++, map) == 0) ? 0 : 1;
>
> Ok, entry is the iova page number. So presumably it's relative to the
> start of dma32_window_start since you're unlikely to have a bitmap that
> covers all of memory. I hadn't realized that previously.
No, it is zero based. The DMA window is a filter but not offset. But you
are right, the it_map does not cover the whole global table (one per PHB,
roughly), will fix it, thanks for pointing. On my test system IOMMU group
is a whole PHB and DMA window always starts from 0 so tests do not show
everything :)
> Doesn't that
> mean that it's actually impossible to create an ioctl based interface to
> the dma64_window since we're not going to know which window is the
> target? I know you're not planning on one, but it seems limiting.
No ,it is not limiting as iova is zero based. Even if it was, there are
flags in map/unmap ioctls which we could use, no?
> We
> at least need some documentation here, but I'm wondering if iova
> shouldn't be zero based so we can determine which window it hits. Also,
> now that I look at it, I can't find any range checking on the iova.
True... Have not hit this problem yet :) Good point, will fix, thanks.
--
Alexey
WARNING: multiple messages have this Message-ID (diff)
From: Alexey Kardashevskiy <aik@ozlabs.ru>
To: Alex Williamson <alex.williamson@redhat.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>,
Paul Mackerras <paulus@samba.org>,
linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org,
David Gibson <david@gibson.dropbear.id.au>
Subject: Re: [PATCH] vfio powerpc: enabled on powernv platform
Date: Sat, 01 Dec 2012 11:14:40 +1100 [thread overview]
Message-ID: <50B94BF0.4080408@ozlabs.ru> (raw)
In-Reply-To: <1354294088.14547.36.camel@ul30vt.home>
On 01/12/12 03:48, Alex Williamson wrote:
> On Fri, 2012-11-30 at 17:14 +1100, Alexey Kardashevskiy wrote:
>> This patch initializes IOMMU groups based on the IOMMU
>> configuration discovered during the PCI scan on POWERNV
>> (POWER non virtualized) platform. The IOMMU groups are
>> to be used later by VFIO driver (PCI pass through).
>>
>> It also implements an API for mapping/unmapping pages for
>> guest PCI drivers and providing DMA window properties.
>> This API is going to be used later by QEMU-VFIO to handle
>> h_put_tce hypercalls from the KVM guest.
>>
>> Although this driver has been tested only on the POWERNV
>> platform, it should work on any platform which supports
>> TCE tables.
>>
>> To enable VFIO on POWER, enable SPAPR_TCE_IOMMU config
>> option and configure VFIO as required.
>>
>> Cc: David Gibson <david@gibson.dropbear.id.au>
>> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
>> ---
>> arch/powerpc/include/asm/iommu.h | 9 ++
>> arch/powerpc/kernel/iommu.c | 186 ++++++++++++++++++++++++++++++++++
>> arch/powerpc/platforms/powernv/pci.c | 135 ++++++++++++++++++++++++
>> drivers/iommu/Kconfig | 8 ++
>> 4 files changed, 338 insertions(+)
>>
>> diff --git a/arch/powerpc/include/asm/iommu.h b/arch/powerpc/include/asm/iommu.h
>> index cbfe678..5c7087a 100644
>> --- a/arch/powerpc/include/asm/iommu.h
>> +++ b/arch/powerpc/include/asm/iommu.h
>> @@ -76,6 +76,9 @@ struct iommu_table {
>> struct iommu_pool large_pool;
>> struct iommu_pool pools[IOMMU_NR_POOLS];
>> unsigned long *it_map; /* A simple allocation bitmap for now */
>> +#ifdef CONFIG_IOMMU_API
>> + struct iommu_group *it_group;
>> +#endif
>> };
>>
>> struct scatterlist;
>> @@ -147,5 +150,11 @@ static inline void iommu_restore(void)
>> }
>> #endif
>>
>> +extern long iommu_clear_tces(struct iommu_table *tbl, unsigned long entry,
>> + unsigned long pages);
>> +extern long iommu_put_tces(struct iommu_table *tbl, unsigned long entry,
>> + uint64_t tce, enum dma_data_direction direction,
>> + unsigned long pages);
>> +
>> #endif /* __KERNEL__ */
>> #endif /* _ASM_IOMMU_H */
>> diff --git a/arch/powerpc/kernel/iommu.c b/arch/powerpc/kernel/iommu.c
>> index ff5a6ce..0646c50 100644
>> --- a/arch/powerpc/kernel/iommu.c
>> +++ b/arch/powerpc/kernel/iommu.c
>> @@ -44,6 +44,7 @@
>> #include <asm/kdump.h>
>> #include <asm/fadump.h>
>> #include <asm/vio.h>
>> +#include <asm/tce.h>
>>
>> #define DBG(...)
>>
>> @@ -856,3 +857,188 @@ void iommu_free_coherent(struct iommu_table *tbl, size_t size,
>> free_pages((unsigned long)vaddr, get_order(size));
>> }
>> }
>> +
>> +#ifdef CONFIG_IOMMU_API
>> +/*
>> + * SPAPR TCE API
>> + */
>> +
>> +/*
>> + * Returns the number of used IOMMU pages (4K) within
>> + * the same system page (4K or 64K).
>> + * bitmap_weight is not used as it does not support bigendian maps.
>> + */
>> +static int syspage_weight(unsigned long *map, unsigned long entry)
>> +{
>> + int ret = 0, nbits = PAGE_SIZE/IOMMU_PAGE_SIZE;
>> +
>> + /* Aligns TCE entry number to system page boundary */
>> + entry &= PAGE_MASK >> IOMMU_PAGE_SHIFT;
>> +
>> + /* Count used 4K pages */
>> + while (nbits--)
>> + ret += (test_bit(entry++, map) == 0) ? 0 : 1;
>
> Ok, entry is the iova page number. So presumably it's relative to the
> start of dma32_window_start since you're unlikely to have a bitmap that
> covers all of memory. I hadn't realized that previously.
No, it is zero based. The DMA window is a filter but not offset. But you
are right, the it_map does not cover the whole global table (one per PHB,
roughly), will fix it, thanks for pointing. On my test system IOMMU group
is a whole PHB and DMA window always starts from 0 so tests do not show
everything :)
> Doesn't that
> mean that it's actually impossible to create an ioctl based interface to
> the dma64_window since we're not going to know which window is the
> target? I know you're not planning on one, but it seems limiting.
No ,it is not limiting as iova is zero based. Even if it was, there are
flags in map/unmap ioctls which we could use, no?
> We
> at least need some documentation here, but I'm wondering if iova
> shouldn't be zero based so we can determine which window it hits. Also,
> now that I look at it, I can't find any range checking on the iova.
True... Have not hit this problem yet :) Good point, will fix, thanks.
--
Alexey
next prev parent reply other threads:[~2012-12-01 0:14 UTC|newest]
Thread overview: 122+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20121113033832.GW4696@truffula.fritz.box>
2012-11-20 0:48 ` [PATCH] vfio powerpc: enabled and supported on powernv platform Alexey Kardashevskiy
2012-11-20 0:48 ` Alexey Kardashevskiy
2012-11-20 18:19 ` Alex Williamson
2012-11-20 18:19 ` Alex Williamson
2012-11-22 11:56 ` Sethi Varun-B16395
2012-11-22 11:56 ` Sethi Varun-B16395
2012-11-22 11:56 ` Sethi Varun-B16395
2012-11-23 2:02 ` Alexey Kardashevskiy
2012-11-23 2:02 ` Alexey Kardashevskiy
2012-11-26 15:18 ` Alex Williamson
2012-11-26 15:18 ` Alex Williamson
2012-11-26 18:04 ` Alex Williamson
2012-11-26 18:04 ` Alex Williamson
2012-11-27 0:21 ` Benjamin Herrenschmidt
2012-11-27 0:21 ` Benjamin Herrenschmidt
2012-11-27 3:28 ` Alexey Kardashevskiy
2012-11-27 3:28 ` Alexey Kardashevskiy
2012-11-27 4:23 ` Alex Williamson
2012-11-27 4:23 ` Alex Williamson
2012-11-26 15:08 ` Alex Williamson
2012-11-26 15:08 ` Alex Williamson
2012-11-23 9:03 ` [PATCH 0/2] vfio powerpc: implemented and enabled Alexey Kardashevskiy
2012-11-23 9:03 ` Alexey Kardashevskiy
2012-11-23 9:03 ` [PATCH 1/2] vfio powerpc: implemented IOMMU driver for VFIO Alexey Kardashevskiy
2012-11-23 9:03 ` Alexey Kardashevskiy
2012-11-26 18:20 ` Alex Williamson
2012-11-26 18:20 ` Alex Williamson
2012-11-27 4:06 ` Alexey Kardashevskiy
2012-11-27 4:06 ` Alexey Kardashevskiy
2012-11-27 4:29 ` Alex Williamson
2012-11-27 4:29 ` Alex Williamson
2012-11-27 4:58 ` Alexey Kardashevskiy
2012-11-27 4:58 ` Alexey Kardashevskiy
2012-11-27 5:06 ` David Gibson
2012-11-27 5:06 ` David Gibson
2012-11-27 5:07 ` Alex Williamson
2012-11-27 5:07 ` Alex Williamson
2012-11-28 7:21 ` [PATCH] " Alexey Kardashevskiy
2012-11-28 7:21 ` Alexey Kardashevskiy
2012-11-28 21:01 ` Alex Williamson
2012-11-28 21:01 ` Alex Williamson
2012-11-29 3:51 ` Alexey Kardashevskiy
2012-11-29 3:51 ` Alexey Kardashevskiy
2012-11-23 9:03 ` [PATCH 2/2] vfio powerpc: enabled on powernv platform Alexey Kardashevskiy
2012-11-23 9:03 ` Alexey Kardashevskiy
2012-11-27 4:41 ` Alex Williamson
2012-11-27 4:41 ` Alex Williamson
2012-11-28 7:18 ` [PATCH] " Alexey Kardashevskiy
2012-11-28 7:18 ` Alexey Kardashevskiy
2012-11-28 21:30 ` Alex Williamson
2012-11-28 21:30 ` Alex Williamson
2012-11-29 3:53 ` Alexey Kardashevskiy
2012-11-29 3:53 ` Alexey Kardashevskiy
2012-11-29 4:20 ` Alex Williamson
2012-11-29 4:20 ` Alex Williamson
2012-11-30 6:14 ` Alexey Kardashevskiy
2012-11-30 6:14 ` Alexey Kardashevskiy
2012-11-30 16:48 ` Alex Williamson
2012-11-30 16:48 ` Alex Williamson
2012-12-01 0:14 ` Alexey Kardashevskiy [this message]
2012-12-01 0:14 ` Alexey Kardashevskiy
2012-11-30 6:16 ` Alexey Kardashevskiy
2012-11-30 6:16 ` Alexey Kardashevskiy
2012-12-03 2:52 ` [PATCH 0/2] vfio on power: yet another try Alexey Kardashevskiy
2012-12-03 2:52 ` Alexey Kardashevskiy
2012-12-03 2:52 ` [PATCH 1/2] vfio powerpc: enabled on powernv platform Alexey Kardashevskiy
2012-12-03 2:52 ` Alexey Kardashevskiy
2012-12-03 17:35 ` Alex Williamson
2012-12-03 17:35 ` Alex Williamson
2012-12-04 8:12 ` Alexey Kardashevskiy
2012-12-04 8:12 ` Alexey Kardashevskiy
2012-12-04 15:51 ` Alex Williamson
2012-12-04 15:51 ` Alex Williamson
2012-12-07 7:35 ` [PATCH] " Alexey Kardashevskiy
2012-12-07 7:35 ` Alexey Kardashevskiy
2012-12-07 17:38 ` Alex Williamson
2012-12-07 17:38 ` Alex Williamson
2012-12-12 6:14 ` Alexey Kardashevskiy
2012-12-12 6:14 ` Alexey Kardashevskiy
2012-12-12 14:34 ` Alex Williamson
2012-12-12 14:34 ` Alex Williamson
2012-12-13 2:29 ` Benjamin Herrenschmidt
2012-12-13 2:29 ` Benjamin Herrenschmidt
2012-12-13 6:27 ` Alexey Kardashevskiy
2012-12-13 6:27 ` Alexey Kardashevskiy
2012-12-13 6:28 ` [PATCH] iommu: moving initialization earlier Alexey Kardashevskiy
[not found] ` <1355380115-4518-1-git-send-email-aik-sLpHqDYs0B2HXe+LvDLADg@public.gmane.org>
2012-12-13 15:48 ` Alex Williamson
2012-12-13 15:48 ` Alex Williamson
[not found] ` <1355413735.2229.1.camel-85EaTFmN5p//9pzu0YdTqQ@public.gmane.org>
2012-12-16 11:20 ` Joerg Roedel
2012-12-16 11:20 ` Joerg Roedel
[not found] ` <20121216112024.GJ1806-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
2013-01-04 8:21 ` Alexey Kardashevskiy
2013-01-04 8:21 ` Alexey Kardashevskiy
[not found] ` <50E6910E.7030103-sLpHqDYs0B2HXe+LvDLADg@public.gmane.org>
2013-01-06 9:49 ` Joerg Roedel
2013-01-06 9:49 ` Joerg Roedel
2012-12-12 12:34 ` [PATCH] vfio powerpc: enabled on powernv platform Alexey Kardashevskiy
2012-12-12 12:34 ` Alexey Kardashevskiy
2012-12-12 12:38 ` Alexey Kardashevskiy
2012-12-12 12:38 ` Alexey Kardashevskiy
2012-12-12 23:30 ` Alex Williamson
2012-12-12 23:30 ` Alex Williamson
2012-12-13 2:24 ` Alexey Kardashevskiy
2012-12-13 2:24 ` Alexey Kardashevskiy
2012-12-13 2:39 ` Benjamin Herrenschmidt
2012-12-13 2:39 ` Benjamin Herrenschmidt
2012-12-13 2:57 ` Benjamin Herrenschmidt
2012-12-13 2:57 ` Benjamin Herrenschmidt
2012-12-13 3:22 ` Alex Williamson
2012-12-13 3:22 ` Alex Williamson
2012-12-03 2:52 ` [PATCH 2/2] vfio powerpc: implemented IOMMU driver for VFIO Alexey Kardashevskiy
2012-12-03 2:52 ` Alexey Kardashevskiy
2012-12-03 17:53 ` Alex Williamson
2012-12-03 17:53 ` Alex Williamson
2012-12-07 7:34 ` [PATCH] " Alexey Kardashevskiy
2012-12-07 7:34 ` Alexey Kardashevskiy
2012-12-07 17:01 ` Alex Williamson
2012-12-07 17:01 ` Alex Williamson
2012-12-12 6:59 ` Alexey Kardashevskiy
2012-12-12 6:59 ` Alexey Kardashevskiy
2012-12-12 14:36 ` Alex Williamson
2012-12-12 14:36 ` Alex Williamson
2012-12-12 12:35 ` Alexey Kardashevskiy
2012-12-12 12:35 ` Alexey Kardashevskiy
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=50B94BF0.4080408@ozlabs.ru \
--to=aik@ozlabs.ru \
--cc=alex.williamson@redhat.com \
--cc=david@gibson.dropbear.id.au \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--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 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.