Skip to contentSkip to conversation

amd iommu: call guest_iommu_set_base from hvmloader

PATCH In review Wei Wang 3 participants 9 messages Sep 26, 2012 – Oct 30, 2012

lore
Share & tools
lore

Wei Wang

author
#0 lore raw

PATCH v6 1/1 amd iommu: call guest_iommu_set_base from hvmloader

From 8110e0a223488a1123fa805051905d8788610cf2 Mon Sep 17 00:00:00 2001
From: Wei Wang <[email protected]>
Date: Wed, 26 Sep 2012 11:44:19 +0200
Subject: [PATCH 2/6] amd iommu: call guest_iommu_set_base from hvmloader.

IOMMU MMIO base address is dynamically allocated by firmware. This patch allows hvmloader to notify hypervisor where the iommu mmio pages are.

---
 xen/arch/x86/hvm/hvm.c          |    4 ++++
 xen/include/public/hvm/params.h |    3 ++-
 2 files changed, 6 insertions(+), 1 deletions(-)
xen/arch/x86/hvm/hvm.c +4 -0
index d69e419..e5c1e32 100644
@@ -66,6 +66,7 @@
 #include <asm/mem_event.h>
 #include <asm/mem_access.h>
 #include <public/mem_event.h>
+#include <asm/hvm/svm/amd-iommu-proto.h>
 
 bool_t __read_mostly hvm_enabled;
 
@@ -3834,6 +3835,9 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE(void) arg)
             case HVM_PARAM_BUFIOREQ_EVTCHN:
                 rc = -EINVAL;
                 break;
+            case HVM_PARAM_IOMMU_BASE:
+                rc = guest_iommu_set_base(d, a.value);
+                break;
             }
 
             if ( rc == 0 ) 
xen/include/public/hvm/params.h +2 -1
index 6b05f61..aab6b7a 100644
@@ -140,7 +140,8 @@
 #define HVM_PARAM_PAGING_RING_PFN   27
 #define HVM_PARAM_ACCESS_RING_PFN   28
 #define HVM_PARAM_SHARING_RING_PFN  29
+#define HVM_PARAM_IOMMU_BASE   30
 
-#define HVM_NR_PARAMS          30
+#define HVM_NR_PARAMS          31
 
 #endif /* __XEN_PUBLIC_HVM_PARAMS_H__ */
Signature · 1 line
1.7.4

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#1 lore raw

xen/arch/x86/hvm/hvm.c long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE(void) arg) · line 3839

Quoted 7 lines
Quoted 1 line
Quoted 1 line · Wei Wang
xen/arch/x86/hvm/hvm.c +2 -0
@@ -3834,6 +3835,9 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE(void) arg)
            case HVM_PARAM_BUFIOREQ_EVTCHN:
                rc = -EINVAL;
                break;
+            case HVM_PARAM_IOMMU_BASE:
+                rc = guest_iommu_set_base(d, a.value);

This suggests that you're allowing for only a single IOMMU per guest - is that not going to become an issue sooner or later?

Jan

Quoted 4 lines
xen/arch/x86/hvm/hvm.c +1 -0
+                break;
            }
 
            if ( rc == 0 ) 
author
#2 lore raw
Quoted 11 lines · Jan Beulich

xen/arch/x86/hvm/hvm.c long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE(void) arg) · line 3839

Quoted 7 lines
Quoted 1 line
Quoted 1 line · Wei Wang
xen/arch/x86/hvm/hvm.c +2 -0
@@ -3834,6 +3835,9 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE(void) arg)
             case HVM_PARAM_BUFIOREQ_EVTCHN:
                 rc = -EINVAL;
                 break;
+            case HVM_PARAM_IOMMU_BASE:
+                rc = guest_iommu_set_base(d, a.value);

This suggests that you're allowing for only a single IOMMU per guest - is that not going to become an issue sooner or later?

Quoted 9 lines

Jan

Quoted 4 lines
xen/arch/x86/hvm/hvm.c +1 -0
+                break;
             }
 
             if ( rc == 0 )

HI Jan,
I think that one iommu per guest is probably enough. Because guest IVRS table is totally virtual, it does not reflect any pci relationship of real systems. Even if qemu supports multi pci buses, we can still virtually group them together into one virtual IVRS table. It might be an issue if qemu uses multi pci segments, but so far even hardware iommu only uses segment 0. Additionally, the guest iommu is only used by ats capable GPUs. Normal passthrough device should not make use of it. So,, What do you think?

Thanks,
Wei

#3 lore raw
Quoted 14 lines
Quoted 1 line
Quoted 1 line · Wei Wang
Quoted 2 lines · Jan Beulich

Review long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE(void)

Quoted 2 lines
Quoted 1 line
Quoted 1 line · Wei Wang
(quoted diff) +0 -0
@@ -3834,6 +3835,9 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE(void) 

arg)

Quoted 8 lines

xen/arch/x86/hvm/hvm.c long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE(void) arg) · line 3839

Quoted 5 lines
xen/arch/x86/hvm/hvm.c +2 -0
             case HVM_PARAM_BUFIOREQ_EVTCHN:
                 rc = -EINVAL;
                 break;
+            case HVM_PARAM_IOMMU_BASE:
+                rc = guest_iommu_set_base(d, a.value);

This suggests that you're allowing for only a single IOMMU per guest - is that not going to become an issue sooner or later?

Quoted 8 lines

I think that one iommu per guest is probably enough. Because guest IVRS table is totally virtual, it does not reflect any pci relationship of real systems. Even if qemu supports multi pci buses, we can still virtually group them together into one virtual IVRS table. It might be an issue if qemu uses multi pci segments, but so far even hardware iommu only uses segment 0. Additionally, the guest iommu is only used by ats capable GPUs. Normal passthrough device should not make use of it. So,, What do you think?

Especially the multi-segment aspect makes me think that the interface should allow for multiple IOMMUs, even if the implementation supports only one for now.

Jan

author
#4 lore raw
Quoted 23 lines · Jan Beulich
Quoted 14 lines
Quoted 1 line
Quoted 1 line · Wei Wang
Quoted 2 lines · Jan Beulich

Review long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE(void)

Quoted 2 lines
Quoted 1 line
Quoted 1 line · Wei Wang
(quoted diff) +0 -0
@@ -3834,6 +3835,9 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE(void)

arg)

Quoted 8 lines

xen/arch/x86/hvm/hvm.c long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE(void) arg) · line 3839

Quoted 5 lines
xen/arch/x86/hvm/hvm.c +2 -0
              case HVM_PARAM_BUFIOREQ_EVTCHN:
                  rc = -EINVAL;
                  break;
+            case HVM_PARAM_IOMMU_BASE:
+                rc = guest_iommu_set_base(d, a.value);

This suggests that you're allowing for only a single IOMMU per guest - is that not going to become an issue sooner or later?

Quoted 8 lines

I think that one iommu per guest is probably enough. Because guest IVRS table is totally virtual, it does not reflect any pci relationship of real systems. Even if qemu supports multi pci buses, we can still virtually group them together into one virtual IVRS table. It might be an issue if qemu uses multi pci segments, but so far even hardware iommu only uses segment 0. Additionally, the guest iommu is only used by ats capable GPUs. Normal passthrough device should not make use of it. So,, What do you think?

Quoted 3 lines

Especially the multi-segment aspect makes me think that the interface should allow for multiple IOMMUs, even if the implementation supports only one for now.

Ok, then I will rework the interface to take iommu segment as an additional parameter. Thanks,
Wei

Quoted 3 lines

Jan

#5 lore raw
Quoted 25 lines
Quoted 1 line
Quoted 1 line · Wei Wang
Quoted 23 lines · Jan Beulich
Quoted 22 lines
Quoted 1 line
Quoted 1 line · Wei Wang
Quoted 2 lines · Jan Beulich

Review long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE(void)

Quoted 2 lines
Quoted 1 line
Quoted 1 line · Wei Wang
(quoted diff) +0 -0
@@ -3834,6 +3835,9 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE(void)

arg)

Quoted 8 lines

xen/arch/x86/hvm/hvm.c long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE(void) arg) · line 3839

Quoted 5 lines
xen/arch/x86/hvm/hvm.c +2 -0
              case HVM_PARAM_BUFIOREQ_EVTCHN:
                  rc = -EINVAL;
                  break;
+            case HVM_PARAM_IOMMU_BASE:
+                rc = guest_iommu_set_base(d, a.value);

This suggests that you're allowing for only a single IOMMU per guest - is that not going to become an issue sooner or later?

I think that one iommu per guest is probably enough. Because guest IVRS table is totally virtual, it does not reflect any pci relationship of real systems. Even if qemu supports multi pci buses, we can still virtually group them together into one virtual IVRS table. It might be an issue if qemu uses multi pci segments, but so far even hardware iommu only uses segment 0. Additionally, the guest iommu is only used by ats capable GPUs. Normal passthrough device should not make use of it. So,, What do you think?

Quoted 6 lines
Quoted 3 lines

Especially the multi-segment aspect makes me think that the interface should allow for multiple IOMMUs, even if the implementation supports only one for now.

Ok, then I will rework the interface to take iommu segment as an additional parameter.

That'll likely make the interface even more ugly than the more flexible variant allowing for multiple IOMMUs independent of the segment they're on/for. But let's see what you come up with...

Jan

author
#6 lore raw
Quoted 29 lines · Jan Beulich
Quoted 29 lines
Quoted 1 line
Quoted 1 line · Wei Wang
Quoted 26 lines · Jan Beulich
Quoted 14 lines
Quoted 1 line
Quoted 1 line · Wei Wang
Quoted 2 lines · Jan Beulich

Review long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE(void)

Quoted 2 lines
Quoted 1 line
Quoted 1 line · Wei Wang
(quoted diff) +0 -0
@@ -3834,6 +3835,9 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE(void)

arg)

Quoted 8 lines

xen/arch/x86/hvm/hvm.c long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE(void) arg) · line 3839

Quoted 5 lines
xen/arch/x86/hvm/hvm.c +2 -0
               case HVM_PARAM_BUFIOREQ_EVTCHN:
                   rc = -EINVAL;
                   break;
+            case HVM_PARAM_IOMMU_BASE:
+                rc = guest_iommu_set_base(d, a.value);

This suggests that you're allowing for only a single IOMMU per guest - is that not going to become an issue sooner or later?

Quoted 8 lines

I think that one iommu per guest is probably enough. Because guest IVRS table is totally virtual, it does not reflect any pci relationship of real systems. Even if qemu supports multi pci buses, we can still virtually group them together into one virtual IVRS table. It might be an issue if qemu uses multi pci segments, but so far even hardware iommu only uses segment 0. Additionally, the guest iommu is only used by ats capable GPUs. Normal passthrough device should not make use of it. So,, What do you think?

Especially the multi-segment aspect makes me think that the interface should allow for multiple IOMMUs, even if the implementation supports only one for now.

Quoted 7 lines
Quoted 2 lines

Ok, then I will rework the interface to take iommu segment as an additional parameter.

That'll likely make the interface even more ugly than the more flexible variant allowing for multiple IOMMUs independent of the segment they're on/for. But let's see what you come up with...

Hi Jan
My idea is to make the interface looks like that
guest_iommu_set_base(d, iommu_base, iommu_seg)

This will allow hvmloader to choose a non-zero iommu segment.
if iommu_seg > 0, then I will add a new iommu to guest iommu list and update iommu_segment field accordingly. But I seem to see no reason to add multiple guest iommus to pci segment 0.

Thanks,
Wei

Quoted 3 lines

Jan

#7 lore raw
Quoted 3 lines
Quoted 1 line
Quoted 1 line · Wei Wang

My idea is to make the interface looks like that
guest_iommu_set_base(d, iommu_base, iommu_seg)

That part is obvious; the more interesting part is how you plan on getting this fix the HVM parameter model.

Quoted 4 lines

This will allow hvmloader to choose a non-zero iommu segment. if iommu_seg > 0, then I will add a new iommu to guest iommu list and update iommu_segment field accordingly. But I seem to see no reason to add multiple guest iommus to pci segment 0.

I don't see a need for this at present too, and as I said before there's no need to implement support for multiple IOMMUs. The interface definition, however, has to be flexible enough so we don't need to introduce another interface in a few years time just because right now we don't expect multiple IOMMUs to be needed for guests (after all, there must be reasons why real hardware frequently comes with more than one IOMMU despite supporting only a single PCI segment - just consider the guest visible NUMA case, where you would quite likely want an IOMMU per guest visible node).

Jan

#8 lore raw
In reply to Wei Wang

Wei Wang wrote on 2012-09-26:

Quoted 1 line

@@ -3834,6 +3835,9 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE(void) arg)

             case HVM_PARAM_BUFIOREQ_EVTCHN:
                 rc = -EINVAL;
                 break;
+            case HVM_PARAM_IOMMU_BASE:
+                rc = guest_iommu_set_base(d, a.value);
+                break;
             }
 
             if ( rc == 0 )

We also have the same function. It's better to use platform specific ops to call it in common file and just leave it as null in intel platform.