RE: [PATCH 1/2] [v2] VT-d: Support multiple device assignment for KVM

2008-12-01 Thread Han, Weidong
It's fine. You only needs to change the APIs to generic APIs. I will update it 
soon.

Regards,
Weidong

Joerg Roedel wrote:
> Ok, I got them to apply. I also did the checkpatch cleanups. To speed
> things up a bit I would suggest that I rebase my patchset on your
> patches and send it out in a single series. Any problems with this
> approach?
> 
> Joerg
> 
> On Mon, Dec 01, 2008 at 09:22:42PM +0800, Han, Weidong wrote:
>> Sorry, this patch has style problem. I will update it and also split
>> it to smaller patches for easy reviewing. 
>> 
>> Regards,
>> Weidong
>> 
>> 'Joerg Roedel' wrote:
>>> Hmm, I get these errors using git-am:
>>> 
>>> Applying VT-d: Support multiple device assignment for KVM
>>> .dotest/patch:1344: space before tab in indent.
>>> clflush_cache_range(addr, size);
>>> .dotest/patch:1350: space before tab in indent.
>>> clflush_cache_range(addr, size);
>>> .dotest/patch:1907: trailing whitespace.
>>> 
>>> .dotest/patch:1946: trailing whitespace.
>>>  * owned by this domain, clear this iommu in
>>> iommu_bmp .dotest/patch:2300: trailing whitespace.
>>> 
>>> error: patch failed: drivers/pci/dmar.c:484
>>> error: drivers/pci/dmar.c: patch does not apply
>>> error: patch failed: drivers/pci/intel-iommu.c:50
>>> error: drivers/pci/intel-iommu.c: patch does not apply
>>> error: patch failed: include/linux/dma_remapping.h:111
>>> error: include/linux/dma_remapping.h: patch does not apply
>>> error: patch failed: include/linux/intel-iommu.h:219
>>> error: include/linux/intel-iommu.h: patch does not apply
>>> Patch failed at 0001.
>>> 
>>> Joerg
>>> 
>> --
>> To unsubscribe from this list: send the line "unsubscribe kvm" in
>> the body of a message to [EMAIL PROTECTED]
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/2] [v2] VT-d: Support multiple device assignment for KVM

2008-12-01 Thread Joerg Roedel
Ok, I got them to apply. I also did the checkpatch cleanups. To speed
things up a bit I would suggest that I rebase my patchset on your
patches and send it out in a single series. Any problems with this
approach?

Joerg

On Mon, Dec 01, 2008 at 09:22:42PM +0800, Han, Weidong wrote:
> Sorry, this patch has style problem. I will update it and also split it to 
> smaller patches for easy reviewing.
> 
> Regards,
> Weidong
> 
> 'Joerg Roedel' wrote:
> > Hmm, I get these errors using git-am:
> > 
> > Applying VT-d: Support multiple device assignment for KVM
> > .dotest/patch:1344: space before tab in indent.
> > clflush_cache_range(addr, size);
> > .dotest/patch:1350: space before tab in indent.
> > clflush_cache_range(addr, size);
> > .dotest/patch:1907: trailing whitespace.
> > 
> > .dotest/patch:1946: trailing whitespace.
> >  * owned by this domain, clear this iommu in iommu_bmp
> > .dotest/patch:2300: trailing whitespace.
> > 
> > error: patch failed: drivers/pci/dmar.c:484
> > error: drivers/pci/dmar.c: patch does not apply
> > error: patch failed: drivers/pci/intel-iommu.c:50
> > error: drivers/pci/intel-iommu.c: patch does not apply
> > error: patch failed: include/linux/dma_remapping.h:111
> > error: include/linux/dma_remapping.h: patch does not apply
> > error: patch failed: include/linux/intel-iommu.h:219
> > error: include/linux/intel-iommu.h: patch does not apply
> > Patch failed at 0001.
> > 
> > Joerg
> > 
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to [EMAIL PROTECTED]
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


RE: [PATCH 1/2] [v2] VT-d: Support multiple device assignment for KVM

2008-12-01 Thread Han, Weidong
Sorry, this patch has style problem. I will update it and also split it to 
smaller patches for easy reviewing.

Regards,
Weidong

'Joerg Roedel' wrote:
> Hmm, I get these errors using git-am:
> 
> Applying VT-d: Support multiple device assignment for KVM
> .dotest/patch:1344: space before tab in indent.
> clflush_cache_range(addr, size);
> .dotest/patch:1350: space before tab in indent.
> clflush_cache_range(addr, size);
> .dotest/patch:1907: trailing whitespace.
> 
> .dotest/patch:1946: trailing whitespace.
>  * owned by this domain, clear this iommu in iommu_bmp
> .dotest/patch:2300: trailing whitespace.
> 
> error: patch failed: drivers/pci/dmar.c:484
> error: drivers/pci/dmar.c: patch does not apply
> error: patch failed: drivers/pci/intel-iommu.c:50
> error: drivers/pci/intel-iommu.c: patch does not apply
> error: patch failed: include/linux/dma_remapping.h:111
> error: include/linux/dma_remapping.h: patch does not apply
> error: patch failed: include/linux/intel-iommu.h:219
> error: include/linux/intel-iommu.h: patch does not apply
> Patch failed at 0001.
> 
> Joerg
> 
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/2] [v2] VT-d: Support multiple device assignment for KVM

2008-12-01 Thread 'Joerg Roedel'
Hmm, I get these errors using git-am:

Applying VT-d: Support multiple device assignment for KVM
.dotest/patch:1344: space before tab in indent.
clflush_cache_range(addr, size);
.dotest/patch:1350: space before tab in indent.
clflush_cache_range(addr, size);
.dotest/patch:1907: trailing whitespace.

.dotest/patch:1946: trailing whitespace.
 * owned by this domain, clear this iommu in iommu_bmp 
.dotest/patch:2300: trailing whitespace.

error: patch failed: drivers/pci/dmar.c:484
error: drivers/pci/dmar.c: patch does not apply
error: patch failed: drivers/pci/intel-iommu.c:50
error: drivers/pci/intel-iommu.c: patch does not apply
error: patch failed: include/linux/dma_remapping.h:111
error: include/linux/dma_remapping.h: patch does not apply
error: patch failed: include/linux/intel-iommu.h:219
error: include/linux/intel-iommu.h: patch does not apply
Patch failed at 0001.

Joerg

On Mon, Dec 01, 2008 at 02:17:38PM +0800, Han, Weidong wrote:
> It's developed based on commit 0f7d3ee6 on avi/master, but it still can be 
> applied on latest avi/master (commit 90755652).
> 
> Regards,
> Weidong
> 
> Joerg Roedel wrote:
> > Hmm, I tried to apply this patch against avi/master and linus/master
> > but get merge conflicts. Where do these patches apply cleanly?
> >
> > Joerg
> >
> > On Thu, Nov 27, 2008 at 09:49:04PM +0800, Han, Weidong wrote:
> >> In order to support multiple device assignment for KVM, this patch
> >> does following main changes:
> >>- extend dmar_domain to own multiple devices from different
> >> iommus, use a bitmap of iommus to replace iommu pointer in
> >> dmar_domain.
> >>- implement independent low level functions for kvm, then won't
> >> impact native VT-d.
> >>- "SAGAW" capability may be different across iommus, that's to
> >> say the VT-d page table levels may be different among iommus. This
> >> patch uses a defaut agaw, and skip top levels of page tables for
> >> iommus which have smaller agaw than default.
> >>- rename the APIs for kvm VT-d, make it more readable.
> >>
> >>
> >> Signed-off-by: Weidong Han <[EMAIL PROTECTED]>
> >> ---
> >>  drivers/pci/dmar.c|   15 +
> >>  drivers/pci/intel-iommu.c |  698
> >>  ++--
> >>  include/linux/dma_remapping.h |   21 +- include/linux/intel-iommu.h
> >>  |   21 +- 4 files changed, 637 insertions(+), 118 deletions(-)
> >>
> >> diff --git a/drivers/pci/dmar.c b/drivers/pci/dmar.c
> >> index 691b3ad..d6bdced 100644
> >> --- a/drivers/pci/dmar.c
> >> +++ b/drivers/pci/dmar.c
> >> @@ -484,6 +484,7 @@ void __init detect_intel_iommu(void)
> >>  dmar_tbl = NULL; }
> >>
> >> +extern int width_to_agaw(int width);
> >>
> >>  int alloc_iommu(struct dmar_drhd_unit *drhd)
> >>  {
> >> @@ -491,6 +492,8 @@ int alloc_iommu(struct dmar_drhd_unit *drhd)
> >> int map_size; u32 ver;
> >> static int iommu_allocated = 0;
> >> +   unsigned long sagaw;
> >> +   int agaw;
> >>
> >> iommu = kzalloc(sizeof(*iommu), GFP_KERNEL); if
> >> (!iommu) @@ -506,6 +509,18 @@ int alloc_iommu(struct dmar_drhd_unit
> >> *drhd) iommu->cap = dmar_readq(iommu->reg + DMAR_CAP_REG);
> >> iommu->ecap = dmar_readq(iommu->reg + DMAR_ECAP_REG);
> >>
> >> +   /* set agaw, "SAGAW" may be different across iommus */
> >> +   sagaw = cap_sagaw(iommu->cap);
> >> +   for (agaw = width_to_agaw(DEFAULT_DOMAIN_ADDRESS_WIDTH);
> >> +agaw >= 0; agaw--)
> >> +   if (test_bit(agaw, &sagaw))
> >> +   break;
> >> +   if (agaw < 0) {
> >> +   printk(KERN_ERR "IOMMU: unsupported sagaw %lx\n",
> >> sagaw); +   goto error; +   }
> >> +   iommu->agaw = agaw;
> >> +
> >> /* the registers might be more than one page */
> >> map_size = max_t(int, ecap_max_iotlb_offset(iommu->ecap),
> >> cap_max_fault_reg_offset(iommu->cap));
> >> diff --git a/drivers/pci/intel-iommu.c b/drivers/pci/intel-iommu.c
> >> index 5c8baa4..55b96c4 100644
> >> --- a/drivers/pci/intel-iommu.c
> >> +++ b/drivers/pci/intel-iommu.c
> >> @@ -50,8 +50,6 @@
> >>  #define IOAPIC_RANGE_END   (0xfeef)
> >>  #define IOVA_START_ADDR(0x1000)
> >>
> >> -#define DEFAULT_DOMAIN_ADDRESS_WIDTH 48
> >> -
> >>  #define DOMAIN_MAX_ADDR(gaw) u64)1) << gaw) - 1)
> >>
> >>
> >> @@ -64,6 +62,7 @@ struct deferred_flush_tables {
> >> int next;
> >> struct iova *iova[HIGH_WATER_MARK];
> >> struct dmar_domain *domain[HIGH_WATER_MARK];
> >> +   struct intel_iommu *iommu;
> >>  };
> >>
> >>  static struct deferred_flush_tables *deferred_flush;
> >> @@ -184,6 +183,69 @@ void free_iova_mem(struct iova *iova)
> >> kmem_cache_free(iommu_iova_cache, iova);
> >>  }
> >>
> >> +/* in native case, each domain is related to only one iommu */
> >> +static struct intel_iommu *domain_get_only_iommu(struct dmar_dom

RE: [PATCH 1/2] [v2] VT-d: Support multiple device assignment for KVM

2008-11-30 Thread Han, Weidong
It's developed based on commit 0f7d3ee6 on avi/master, but it still can be 
applied on latest avi/master (commit 90755652).

Regards,
Weidong

Joerg Roedel wrote:
> Hmm, I tried to apply this patch against avi/master and linus/master
> but get merge conflicts. Where do these patches apply cleanly?
>
> Joerg
>
> On Thu, Nov 27, 2008 at 09:49:04PM +0800, Han, Weidong wrote:
>> In order to support multiple device assignment for KVM, this patch
>> does following main changes:
>>- extend dmar_domain to own multiple devices from different
>> iommus, use a bitmap of iommus to replace iommu pointer in
>> dmar_domain.
>>- implement independent low level functions for kvm, then won't
>> impact native VT-d.
>>- "SAGAW" capability may be different across iommus, that's to
>> say the VT-d page table levels may be different among iommus. This
>> patch uses a defaut agaw, and skip top levels of page tables for
>> iommus which have smaller agaw than default.
>>- rename the APIs for kvm VT-d, make it more readable.
>>
>>
>> Signed-off-by: Weidong Han <[EMAIL PROTECTED]>
>> ---
>>  drivers/pci/dmar.c|   15 +
>>  drivers/pci/intel-iommu.c |  698
>>  ++--
>>  include/linux/dma_remapping.h |   21 +- include/linux/intel-iommu.h
>>  |   21 +- 4 files changed, 637 insertions(+), 118 deletions(-)
>>
>> diff --git a/drivers/pci/dmar.c b/drivers/pci/dmar.c
>> index 691b3ad..d6bdced 100644
>> --- a/drivers/pci/dmar.c
>> +++ b/drivers/pci/dmar.c
>> @@ -484,6 +484,7 @@ void __init detect_intel_iommu(void)
>>  dmar_tbl = NULL; }
>>
>> +extern int width_to_agaw(int width);
>>
>>  int alloc_iommu(struct dmar_drhd_unit *drhd)
>>  {
>> @@ -491,6 +492,8 @@ int alloc_iommu(struct dmar_drhd_unit *drhd)
>> int map_size; u32 ver;
>> static int iommu_allocated = 0;
>> +   unsigned long sagaw;
>> +   int agaw;
>>
>> iommu = kzalloc(sizeof(*iommu), GFP_KERNEL); if
>> (!iommu) @@ -506,6 +509,18 @@ int alloc_iommu(struct dmar_drhd_unit
>> *drhd) iommu->cap = dmar_readq(iommu->reg + DMAR_CAP_REG);
>> iommu->ecap = dmar_readq(iommu->reg + DMAR_ECAP_REG);
>>
>> +   /* set agaw, "SAGAW" may be different across iommus */
>> +   sagaw = cap_sagaw(iommu->cap);
>> +   for (agaw = width_to_agaw(DEFAULT_DOMAIN_ADDRESS_WIDTH);
>> +agaw >= 0; agaw--)
>> +   if (test_bit(agaw, &sagaw))
>> +   break;
>> +   if (agaw < 0) {
>> +   printk(KERN_ERR "IOMMU: unsupported sagaw %lx\n",
>> sagaw); +   goto error; +   }
>> +   iommu->agaw = agaw;
>> +
>> /* the registers might be more than one page */
>> map_size = max_t(int, ecap_max_iotlb_offset(iommu->ecap),
>> cap_max_fault_reg_offset(iommu->cap));
>> diff --git a/drivers/pci/intel-iommu.c b/drivers/pci/intel-iommu.c
>> index 5c8baa4..55b96c4 100644
>> --- a/drivers/pci/intel-iommu.c
>> +++ b/drivers/pci/intel-iommu.c
>> @@ -50,8 +50,6 @@
>>  #define IOAPIC_RANGE_END   (0xfeef)
>>  #define IOVA_START_ADDR(0x1000)
>>
>> -#define DEFAULT_DOMAIN_ADDRESS_WIDTH 48
>> -
>>  #define DOMAIN_MAX_ADDR(gaw) u64)1) << gaw) - 1)
>>
>>
>> @@ -64,6 +62,7 @@ struct deferred_flush_tables {
>> int next;
>> struct iova *iova[HIGH_WATER_MARK];
>> struct dmar_domain *domain[HIGH_WATER_MARK];
>> +   struct intel_iommu *iommu;
>>  };
>>
>>  static struct deferred_flush_tables *deferred_flush;
>> @@ -184,6 +183,69 @@ void free_iova_mem(struct iova *iova)
>> kmem_cache_free(iommu_iova_cache, iova);
>>  }
>>
>> +/* in native case, each domain is related to only one iommu */
>> +static struct intel_iommu *domain_get_only_iommu(struct dmar_domain
>> *domain) +{ +   struct dmar_drhd_unit *drhd;
>> +
>> +   for_each_drhd_unit(drhd) {
>> +   if (drhd->ignored)
>> +   continue;
>> +   if (test_bit(drhd->iommu->seq_id,
>> &domain->iommu_bmp)) +   return drhd->iommu;
>> +   }
>> +
>> +   return NULL;
>> +}
>> +
>> +static void domain_flush_cache(struct dmar_domain *domain,
>> +  void *addr, int size) +{
>> +   struct intel_iommu *iommu;
>> +
>> +   if (domain->flags & DOMAIN_FLAG_VIRTUAL_MACHINE) {
>> +   struct dmar_drhd_unit *drhd;
>> +
>> +   for_each_drhd_unit(drhd) {
>> +   if (drhd->ignored)
>> +   continue;
>> +   iommu = drhd->iommu;
>> +
>> +   if (!test_bit(iommu->seq_id,
>> &domain->iommu_bmp)) +   continue;
>> +
>> +   if (!ecap_coherent(iommu->ecap))
>> +   clflush_cache_range(addr, size); +
>> } +   }
>> +   else {
>> +   iommu = domain_get_only_iommu(domain);
>> +   if (iommu && !ecap_coherent(iommu->e

Re: [PATCH 1/2] [v2] VT-d: Support multiple device assignment for KVM

2008-11-28 Thread Joerg Roedel
Hmm, I tried to apply this patch against avi/master and linus/master but
get merge conflicts. Where do these patches apply cleanly?

Joerg

On Thu, Nov 27, 2008 at 09:49:04PM +0800, Han, Weidong wrote:
> In order to support multiple device assignment for KVM, this patch does 
> following main changes:
>- extend dmar_domain to own multiple devices from different iommus, use a 
> bitmap of iommus to replace iommu pointer in dmar_domain.
>- implement independent low level functions for kvm, then won't impact 
> native VT-d.
>- "SAGAW" capability may be different across iommus, that's to say the 
> VT-d page table levels may be different among iommus. This patch uses a 
> defaut agaw, and skip top levels of page tables for iommus which have smaller 
> agaw than default.
>- rename the APIs for kvm VT-d, make it more readable.
> 
> 
> Signed-off-by: Weidong Han <[EMAIL PROTECTED]>
> ---
>  drivers/pci/dmar.c|   15 +
>  drivers/pci/intel-iommu.c |  698 ++--
>  include/linux/dma_remapping.h |   21 +-
>  include/linux/intel-iommu.h   |   21 +-
>  4 files changed, 637 insertions(+), 118 deletions(-)
> 
> diff --git a/drivers/pci/dmar.c b/drivers/pci/dmar.c
> index 691b3ad..d6bdced 100644
> --- a/drivers/pci/dmar.c
> +++ b/drivers/pci/dmar.c
> @@ -484,6 +484,7 @@ void __init detect_intel_iommu(void)
> dmar_tbl = NULL;
>  }
> 
> +extern int width_to_agaw(int width);
> 
>  int alloc_iommu(struct dmar_drhd_unit *drhd)
>  {
> @@ -491,6 +492,8 @@ int alloc_iommu(struct dmar_drhd_unit *drhd)
> int map_size;
> u32 ver;
> static int iommu_allocated = 0;
> +   unsigned long sagaw;
> +   int agaw;
> 
> iommu = kzalloc(sizeof(*iommu), GFP_KERNEL);
> if (!iommu)
> @@ -506,6 +509,18 @@ int alloc_iommu(struct dmar_drhd_unit *drhd)
> iommu->cap = dmar_readq(iommu->reg + DMAR_CAP_REG);
> iommu->ecap = dmar_readq(iommu->reg + DMAR_ECAP_REG);
> 
> +   /* set agaw, "SAGAW" may be different across iommus */
> +   sagaw = cap_sagaw(iommu->cap);
> +   for (agaw = width_to_agaw(DEFAULT_DOMAIN_ADDRESS_WIDTH);
> +agaw >= 0; agaw--)
> +   if (test_bit(agaw, &sagaw))
> +   break;
> +   if (agaw < 0) {
> +   printk(KERN_ERR "IOMMU: unsupported sagaw %lx\n", sagaw);
> +   goto error;
> +   }
> +   iommu->agaw = agaw;
> +
> /* the registers might be more than one page */
> map_size = max_t(int, ecap_max_iotlb_offset(iommu->ecap),
> cap_max_fault_reg_offset(iommu->cap));
> diff --git a/drivers/pci/intel-iommu.c b/drivers/pci/intel-iommu.c
> index 5c8baa4..55b96c4 100644
> --- a/drivers/pci/intel-iommu.c
> +++ b/drivers/pci/intel-iommu.c
> @@ -50,8 +50,6 @@
>  #define IOAPIC_RANGE_END   (0xfeef)
>  #define IOVA_START_ADDR(0x1000)
> 
> -#define DEFAULT_DOMAIN_ADDRESS_WIDTH 48
> -
>  #define DOMAIN_MAX_ADDR(gaw) u64)1) << gaw) - 1)
> 
> 
> @@ -64,6 +62,7 @@ struct deferred_flush_tables {
> int next;
> struct iova *iova[HIGH_WATER_MARK];
> struct dmar_domain *domain[HIGH_WATER_MARK];
> +   struct intel_iommu *iommu;
>  };
> 
>  static struct deferred_flush_tables *deferred_flush;
> @@ -184,6 +183,69 @@ void free_iova_mem(struct iova *iova)
> kmem_cache_free(iommu_iova_cache, iova);
>  }
> 
> +/* in native case, each domain is related to only one iommu */
> +static struct intel_iommu *domain_get_only_iommu(struct dmar_domain *domain)
> +{
> +   struct dmar_drhd_unit *drhd;
> +
> +   for_each_drhd_unit(drhd) {
> +   if (drhd->ignored)
> +   continue;
> +   if (test_bit(drhd->iommu->seq_id, &domain->iommu_bmp))
> +   return drhd->iommu;
> +   }
> +
> +   return NULL;
> +}
> +
> +static void domain_flush_cache(struct dmar_domain *domain,
> +  void *addr, int size)
> +{
> +   struct intel_iommu *iommu;
> +
> +   if (domain->flags & DOMAIN_FLAG_VIRTUAL_MACHINE) {
> +   struct dmar_drhd_unit *drhd;
> +
> +   for_each_drhd_unit(drhd) {
> +   if (drhd->ignored)
> +   continue;
> +   iommu = drhd->iommu;
> +
> +   if (!test_bit(iommu->seq_id, &domain->iommu_bmp))
> +   continue;
> +
> +   if (!ecap_coherent(iommu->ecap))
> +   clflush_cache_range(addr, size);
> +   }
> +   }
> +   else {
> +   iommu = domain_get_only_iommu(domain);
> +   if (iommu && !ecap_coherent(iommu->ecap))
> +   clflush_cache_range(addr, size);
> +   }
> +}
> +
> +static struct intel_iommu *device_find_matched_iommu(u8 bus, u8 devfn)
> +{
> +   struct dmar_drhd_unit *drhd = NULL;
> +   int i;
>