intel-iommu: ignore SNP bit in scalable mode
Subsystems (2)
PATCH 1/1 intel-iommu: ignore SNP bit in scalable mode
When booting with scalable mode, I hit this error:
qemu-system-x86_64: vtd_iova_to_slpte: detected splte reserve non-zero iova=0xfffff002, level=0x1slpte=0x102681803)
qemu-system-x86_64: vtd_iommu_translate: detected translation failure (dev=01:00:00, iova=0xfffff002)
qemu-system-x86_64: New fault is not recorded due to compression of faults
This is because the SNP bit is set since Linux kernel commit 6c00612d0cba1 ("iommu/vt-d: Report right snoop capability when using FL for IOVA") where SNP bit is set if scalable mode is on though this seems to be an violation on the spec which said the SNP bit is considered to be reserved if SC is not supported.
To unbreak the guest, ignore the SNP bit for scalable mode first. In the future we may consider to add SC support.
--- hw/i386/intel_iommu.c | 18 ++++++++++++------ hw/i386/intel_iommu_internal.h | 2 ++ 2 files changed, 14 insertions(+), 6 deletions(-)
hw/i386/intel_iommu.c +12 -6
@@ -969,7 +969,8 @@ static dma_addr_t vtd_get_iova_pgtbl_base(IntelIOMMUState *s,static uint64_t vtd_spte_rsvd[5 ];static uint64_t vtd_spte_rsvd_large[5 ]; -static bool vtd_slpte_nonzero_rsvd (uint64_t slpte,uint32_t level) +static bool vtd_slpte_nonzero_rsvd (IntelIOMMUState *s, +uint64_t slpte,uint32_t level) {uint64_t rsvd_mask = vtd_spte_rsvd[level];
@@ -979,6 +980,10 @@ static bool vtd_slpte_nonzero_rsvd(uint64_t slpte, uint32_t level) rsvd_mask = vtd_spte_rsvd_large[level]; } +if (s->scalable_mode) { + rsvd_mask &= ~VTD_SPTE_SNP ; + } +return slpte & rsvd_mask; }
@@ -1054,7 +1059,7 @@ static int vtd_iova_to_slpte(IntelIOMMUState *s, VTDContextEntry *ce, iova, level, slpte, is_write);return is_write ? -VTD_FR_WRITE : -VTD_FR_READ ; } -if (vtd_slpte_nonzero_rsvd (slpte, level)) { +if (vtd_slpte_nonzero_rsvd (s, slpte, level)) { error_report_once("%s: detected splte reserve non-zero " "iova=0x%" PRIx64 ", level=0x%" PRIx32 "slpte=0x%" PRIx64 ")", __func__, iova,
@@ -1185,7 +1190,8 @@ static int vtd_page_walk_one(IOMMUTLBEvent *event, vtd_page_walk_info *info)* @write: whether parent level has write permission * @info: constant information for the page walk */ -static int vtd_page_walk_level (dma_addr_t addr,uint64_t start, +static int vtd_page_walk_level (IntelIOMMUState *s, +dma_addr_t addr,uint64_t start,uint64_t end,uint32_t level,bool read,bool write,vtd_page_walk_info *info) {
@@ -1214,7 +1220,7 @@ static int vtd_page_walk_level(dma_addr_t addr, uint64_t start, goto next; } -if (vtd_slpte_nonzero_rsvd (slpte, level)) { +if (vtd_slpte_nonzero_rsvd (s, slpte, level)) {trace_vtd_page_walk_skip_reserve (iova, iova_next); goto next; }
@@ -1235,7 +1241,7 @@ static int vtd_page_walk_level(dma_addr_t addr, uint64_t start,* This is a valid PDE (or even bigger than PDE). We need * to walk one further level. */ - ret =vtd_page_walk_level (vtd_get_slpte_addr (slpte, info->aw), + ret =vtd_page_walk_level (s,vtd_get_slpte_addr (slpte, info->aw), iova,MIN (iova_next, end), level -1 , read_cur, write_cur, info); }else {
@@ -1294,7 +1300,7 @@ static int vtd_page_walk(IntelIOMMUState *s, VTDContextEntry *ce, end =vtd_iova_limit (s, ce, info->aw); } -return vtd_page_walk_level (addr, start, end, level, true, true, info); +return vtd_page_walk_level (s, addr, start, end, level, true, true, info); } static int vtd_root_entry_rsvd_bits_check(IntelIOMMUState *s,
hw/i386/intel_iommu_internal.h +2 -0
@@ -388,6 +388,8 @@ typedef union VTDInvDesc VTDInvDesc;#define VTD_INV_DESC_DEVICE_IOTLB_RSVD_LO 0xffff0000ffe0fff8/* Rsvd field masks for spte */ +#define VTD_SPTE_SNP 0x800ULL +#define VTD_SPTE_PAGE_L1_RSVD_MASK (aw, dt_supported) \ dt_supported ? \ (0x800ULL | ~(VTD_HAW_MASK(aw) | VTD_SL_IGN_COM | VTD_SL_TM)) : \
Signature · 1 line
2.25.1
Quoted 11 lines · Jason Wang
When booting with scalable mode, I hit this error:
qemu-system-x86_64:
vtd_iova_to_slpte: detected splte reserve non-zero iova=0xfffff002, level=0x1slpte=0x102681803)
qemu-system-x86_64:vtd_iommu_translate: detected translation failure (dev=01:00:00, iova=0xfffff002)
qemu-system-x86_64: New fault is not recorded due to compression of faultsThis is because the SNP bit is set since Linux kernel commit
6c00612d0cba1("iommu/vt-d: Report right snoop capability when using FL for IOVA") where SNP bit is set if scalable mode is on though this seems to be an violation on the spec which said the SNP bit is considered to be reserved if SC is not supported.
When I was reading that commit, I was actually confused by this change:
---8<---
drivers/iommu/intel/iommu.c +8 -1
@@ -658,7 +658,14 @@ static int domain_update_iommu_snooping(struct intel_iommu *skip)rcu_read_lock ();for_each_active_iommu (iommu, drhd) {if (iommu != skip) { -if (!ecap_sc_support (iommu->ecap)) { +/* +* If the hardware is operating in the scalable mode, +* the snooping control is always supported since we +* always set PASID-table-entry.PGSNP bit if the domain +* is managed outside (UNMANAGED). +*/ +if (!sm_supported (iommu) && + !ecap_sc_support (iommu->ecap)) { ret =0 ;break ; }
---8<---
Does it mean that for some hardwares that has sm_supported()==true, it'll have SC bit cleared in ecap register? That sounds odd, and not sure why. Maybe Yi Liu or Yi Sun may know?
Quoted 3 lines
To unbreak the guest, ignore the SNP bit for scalable mode first. In the future we may consider to add SC support.
Oh yes, I remembered the last time we discussed this. Could you remind me what's missing for us to support SC?
IIUC, for common device emulations we can just declare SC==1, right? As all the DMAs (including kernel accels like vhost) will be from host processors so there're no coherent issues with guest vcpu threads.
If that's correct, the only challenge is device assignment in any form (I am not familiar with vdpa; so perhaps that includes vfio, vpda and any other kind of assigning host devices to guest?), then we'll try to detect IOMMU_CACHE capability from the host iommu groups that covers the assigned devices, and we only set SC==1 if we have cache coherency on all the devices?
Quoted 22 lines
Signed-off-by Jason Wang <[email protected]>--- hw/i386/intel_iommu.c | 18 ++++++++++++------ hw/i386/intel_iommu_internal.h | 2 ++ 2 files changed, 14 insertions(+), 6 deletions(-)hw/i386/intel_iommu.c +2
-1@@ -969,7 +969,8 @@ static dma_addr_t vtd_get_iova_pgtbl_base(IntelIOMMUState *s,static uint64_t vtd_spte_rsvd[5 ];static uint64_t vtd_spte_rsvd_large[5 ]; -static bool vtd_slpte_nonzero_rsvd (uint64_t slpte,uint32_t level) +static bool vtd_slpte_nonzero_rsvd (IntelIOMMUState *s, +uint64_t slpte,uint32_t level) {uint64_t rsvd_mask = vtd_spte_rsvd[level];
hw/i386/intel_iommu.c static bool vtd_slpte_nonzero_rsvd(uint64_t slpte, uint32_t level) · line 985
Quoted 6 lines
hw/i386/intel_iommu.c +3
-0@@ -979,6 +980,10 @@ static bool vtd_slpte_nonzero_rsvd(uint64_t slpte, uint32_t level) rsvd_mask = vtd_spte_rsvd_large[level]; } +if (s->scalable_mode) { + rsvd_mask &= ~VTD_SPTE_SNP ; + }
IMHO what we want to do is only to skip the leaves of pgtables on SNP, so maybe we still want to keep checking the bit 11 reserved for e.g. common pgtable dir entries?
To do so, how about directly modifying the vtd_spte_rsvd* fields in vtd_init()? I think we only need to modify 4k/2m/1g entries to mask bit 11, they're:
- vtd_spte_rsvd[1] (4K)
- vtd_spte_rsvd_large[2] (2M)
- vtd_spte_rsvd_large[3] (1G)
What do you think? Then we avoid passing IntelIOMMUState* all over too.
Quoted 66 lines
hw/i386/intel_iommu.c +7
-5+return slpte & rsvd_mask; }@@ -1054,7 +1059,7 @@ static int vtd_iova_to_slpte(IntelIOMMUState *s, VTDContextEntry *ce, iova, level, slpte, is_write);return is_write ? -VTD_FR_WRITE : -VTD_FR_READ ; } -if (vtd_slpte_nonzero_rsvd (slpte, level)) { +if (vtd_slpte_nonzero_rsvd (s, slpte, level)) { error_report_once("%s: detected splte reserve non-zero " "iova=0x%" PRIx64 ", level=0x%" PRIx32 "slpte=0x%" PRIx64 ")", __func__, iova,@@ -1185,7 +1190,8 @@ static int vtd_page_walk_one(IOMMUTLBEvent *event, vtd_page_walk_info *info)* @write: whether parent level has write permission * @info: constant information for the page walk */ -static int vtd_page_walk_level (dma_addr_t addr,uint64_t start, +static int vtd_page_walk_level (IntelIOMMUState *s, +dma_addr_t addr,uint64_t start,uint64_t end,uint32_t level,bool read,bool write,vtd_page_walk_info *info) {@@ -1214,7 +1220,7 @@ static int vtd_page_walk_level(dma_addr_t addr, uint64_t start, goto next; } -if (vtd_slpte_nonzero_rsvd (slpte, level)) { +if (vtd_slpte_nonzero_rsvd (s, slpte, level)) {trace_vtd_page_walk_skip_reserve (iova, iova_next); goto next; }@@ -1235,7 +1241,7 @@ static int vtd_page_walk_level(dma_addr_t addr, uint64_t start,* This is a valid PDE (or even bigger than PDE). We need * to walk one further level. */ - ret =vtd_page_walk_level (vtd_get_slpte_addr (slpte, info->aw), + ret =vtd_page_walk_level (s,vtd_get_slpte_addr (slpte, info->aw), iova,MIN (iova_next, end), level -1 , read_cur, write_cur, info); }else {@@ -1294,7 +1300,7 @@ static int vtd_page_walk(IntelIOMMUState *s, VTDContextEntry *ce, end =vtd_iova_limit (s, ce, info->aw); } -return vtd_page_walk_level (addr, start, end, level, true, true, info); +return vtd_page_walk_level (s, addr, start, end, level, true, true, info); } static int vtd_root_entry_rsvd_bits_check(IntelIOMMUState *s,hw/i386/intel_iommu_internal.h +2
-0@@ -388,6 +388,8 @@ typedef union VTDInvDesc VTDInvDesc;#define VTD_INV_DESC_DEVICE_IOTLB_RSVD_LO 0xffff0000ffe0fff8/* Rsvd field masks for spte */ +#define VTD_SPTE_SNP 0x800ULL +#define VTD_SPTE_PAGE_L1_RSVD_MASK (aw, dt_supported) \ dt_supported ? \ (0x800ULL | ~(VTD_HAW_MASK(aw) | VTD_SL_IGN_COM | VTD_SL_TM)) : \Signature · 1 line
2.25.1
Signature · 1 line
Peter Xu
Quoted 39 lines · Peter Xu
Quoted 11 lines · Jason Wang
When booting with scalable mode, I hit this error:
qemu-system-x86_64:
vtd_iova_to_slpte: detected splte reserve non-zero iova=0xfffff002, level=0x1slpte=0x102681803)
qemu-system-x86_64:vtd_iommu_translate: detected translation failure (dev=01:00:00, iova=0xfffff002)
qemu-system-x86_64: New fault is not recorded due to compression of faultsThis is because the SNP bit is set since Linux kernel commit
6c00612d0cba1("iommu/vt-d: Report right snoop capability when using FL for IOVA") where SNP bit is set if scalable mode is on though this seems to be an violation on the spec which said the SNP bit is considered to be reserved if SC is not supported.When I was reading that commit, I was actually confused by this change:
---8<---
drivers/iommu/intel/iommu.c +8
-2@@ -658,7 +658,14 @@ static int domain_update_iommu_snooping(struct intel_iommu *skip)rcu_read_lock ();for_each_active_iommu (iommu, drhd) {if (iommu != skip) { -if (!ecap_sc_support (iommu->ecap)) { +/* +* If the hardware is operating in the scalable mode, +* the snooping control is always supported since we +* always set PASID-table-entry.PGSNP bit if the domain +* is managed outside (UNMANAGED). +*/ +if (!sm_supported (iommu) && + !ecap_sc_support (iommu->ecap)) { ret =0 ;break ; } ---8<---
Quoted 2 lines
Does it mean that for some hardwares that has sm_supported()==true, it'll have SC bit cleared in ecap register?
I guess not, so it's probably only the problem of vIOMMU.
Quoted 2 lines
That sounds odd, and not sure why. Maybe Yi
Liu or Yi Sun may know?
Another interesting point is that, it looks to me after that commit SNP is used for the domain that is not UNMANAGED even if PGSNP is not set.
Quoted 7 lines
Quoted 4 lines
To unbreak the guest, ignore the SNP bit for scalable mode first. In the future we may consider to add SC support.
Oh yes, I remembered the last time we discussed this. Could you remind me what's missing for us to support SC?
Exactly what you described below.
Quoted 2 lines
IIUC, for common device emulations we can just declare SC==1, right?
Strictly speaking, only safe for the datapath that is running in the Qemu. For things like vhost-user, I'm not sure it can check CC when using VFIO.
Quoted 9 lines
As all
the DMAs (including kernel accels like vhost) will be from host processors so there're no coherent issues with guest vcpu threads.If that's correct, the only challenge is device assignment in any form (I am not familiar with vdpa; so perhaps that includes vfio, vpda and any other kind of assigning host devices to guest?), then we'll try to detect
IOMMU_CACHEcapability from the host iommu groups that covers the assigned devices, and we only set SC==1 if we have cache coherency on all the devices?
For VFIO yes, and we should prevent VFIO without CC to be plugged if SC is advertised.
For vDPA, we don't need to worry about it at all, kernel vDPA forces IOMMU_CACHE now.
vhost_vdpa_alloc_domain():
if (!iommu_capable(bus, IOMMU_CAP_CACHE_COHERENCY))
return -ENOTSUPP;
(For device with on-chip IOMMU, it's the parent and device that guarantees the CC)
Thanks
Quoted 113 lines
Quoted 23 lines
Signed-off-by Jason Wang <[email protected]>--- hw/i386/intel_iommu.c | 18 ++++++++++++------ hw/i386/intel_iommu_internal.h | 2 ++ 2 files changed, 14 insertions(+), 6 deletions(-)hw/i386/intel_iommu.c +2
-1@@ -969,7 +969,8 @@ static dma_addr_t vtd_get_iova_pgtbl_base(IntelIOMMUState *s,static uint64_t vtd_spte_rsvd[5 ];static uint64_t vtd_spte_rsvd_large[5 ]; -static bool vtd_slpte_nonzero_rsvd (uint64_t slpte,uint32_t level) +static bool vtd_slpte_nonzero_rsvd (IntelIOMMUState *s, +uint64_t slpte,uint32_t level) {uint64_t rsvd_mask = vtd_spte_rsvd[level];hw/i386/intel_iommu.c static bool vtd_slpte_nonzero_rsvd(uint64_t slpte, uint32_t level) · line 985
Quoted 6 lines
hw/i386/intel_iommu.c +3
-0@@ -979,6 +980,10 @@ static bool vtd_slpte_nonzero_rsvd(uint64_t slpte, uint32_t level) rsvd_mask = vtd_spte_rsvd_large[level]; } +if (s->scalable_mode) { + rsvd_mask &= ~VTD_SPTE_SNP ; + }IMHO what we want to do is only to skip the leaves of pgtables on SNP, so maybe we still want to keep checking the bit 11 reserved for e.g. common pgtable dir entries?
To do so, how about directly modifying the vtd_spte_rsvd* fields in
vtd_init()? I think we only need to modify 4k/2m/1g entries to mask bit 11, they're:- vtd_spte_rsvd[1] (4K)
- vtd_spte_rsvd_large[2] (2M)
- vtd_spte_rsvd_large[3] (1G)What do you think? Then we avoid passing IntelIOMMUState* all over too.
Quoted 64 lines
hw/i386/intel_iommu.c +7
-5+return slpte & rsvd_mask; }@@ -1054,7 +1059,7 @@ static int vtd_iova_to_slpte(IntelIOMMUState *s, VTDContextEntry *ce, iova, level, slpte, is_write);return is_write ? -VTD_FR_WRITE : -VTD_FR_READ ; } -if (vtd_slpte_nonzero_rsvd (slpte, level)) { +if (vtd_slpte_nonzero_rsvd (s, slpte, level)) { error_report_once("%s: detected splte reserve non-zero " "iova=0x%" PRIx64 ", level=0x%" PRIx32 "slpte=0x%" PRIx64 ")", __func__, iova,@@ -1185,7 +1190,8 @@ static int vtd_page_walk_one(IOMMUTLBEvent *event, vtd_page_walk_info *info)* @write: whether parent level has write permission * @info: constant information for the page walk */ -static int vtd_page_walk_level (dma_addr_t addr,uint64_t start, +static int vtd_page_walk_level (IntelIOMMUState *s, +dma_addr_t addr,uint64_t start,uint64_t end,uint32_t level,bool read,bool write,vtd_page_walk_info *info) {@@ -1214,7 +1220,7 @@ static int vtd_page_walk_level(dma_addr_t addr, uint64_t start, goto next; } -if (vtd_slpte_nonzero_rsvd (slpte, level)) { +if (vtd_slpte_nonzero_rsvd (s, slpte, level)) {trace_vtd_page_walk_skip_reserve (iova, iova_next); goto next; }@@ -1235,7 +1241,7 @@ static int vtd_page_walk_level(dma_addr_t addr, uint64_t start,* This is a valid PDE (or even bigger than PDE). We need * to walk one further level. */ - ret =vtd_page_walk_level (vtd_get_slpte_addr (slpte, info->aw), + ret =vtd_page_walk_level (s,vtd_get_slpte_addr (slpte, info->aw), iova,MIN (iova_next, end), level -1 , read_cur, write_cur, info); }else {@@ -1294,7 +1300,7 @@ static int vtd_page_walk(IntelIOMMUState *s, VTDContextEntry *ce, end =vtd_iova_limit (s, ce, info->aw); } -return vtd_page_walk_level (addr, start, end, level, true, true, info); +return vtd_page_walk_level (s, addr, start, end, level, true, true, info); } static int vtd_root_entry_rsvd_bits_check(IntelIOMMUState *s,hw/i386/intel_iommu_internal.h +2
-1@@ -388,6 +388,8 @@ typedef union VTDInvDesc VTDInvDesc;#define VTD_INV_DESC_DEVICE_IOTLB_RSVD_LO 0xffff0000ffe0fff8/* Rsvd field masks for spte */ +#define VTD_SPTE_SNP 0x800ULL +#define VTD_SPTE_PAGE_L1_RSVD_MASK (aw, dt_supported) \ dt_supported ? \ (0x800ULL | ~(VTD_HAW_MASK(aw) | VTD_SL_IGN_COM | VTD_SL_TM)) : \ --Quoted 2 lines
2.25.1
--
Peter Xu
Quoted 40 lines · Jason Wang
Quoted 39 lines · Peter Xu
Quoted 11 lines · Jason Wang
When booting with scalable mode, I hit this error:
qemu-system-x86_64:
vtd_iova_to_slpte: detected splte reserve non-zero iova=0xfffff002, level=0x1slpte=0x102681803)
qemu-system-x86_64:vtd_iommu_translate: detected translation failure (dev=01:00:00, iova=0xfffff002)
qemu-system-x86_64: New fault is not recorded due to compression of faultsThis is because the SNP bit is set since Linux kernel commit
6c00612d0cba1("iommu/vt-d: Report right snoop capability when using FL for IOVA") where SNP bit is set if scalable mode is on though this seems to be an violation on the spec which said the SNP bit is considered to be reserved if SC is not supported.When I was reading that commit, I was actually confused by this change:
---8<---
drivers/iommu/intel/iommu.c +8
-2@@ -658,7 +658,14 @@ static int domain_update_iommu_snooping(struct intel_iommu *skip)rcu_read_lock ();for_each_active_iommu (iommu, drhd) {if (iommu != skip) { -if (!ecap_sc_support (iommu->ecap)) { +/* +* If the hardware is operating in the scalable mode, +* the snooping control is always supported since we +* always set PASID-table-entry.PGSNP bit if the domain +* is managed outside (UNMANAGED). +*/ +if (!sm_supported (iommu) && + !ecap_sc_support (iommu->ecap)) { ret =0 ;break ; } ---8<---
Quoted 4 lines
Quoted 2 lines
Does it mean that for some hardwares that has sm_supported()==true, it'll have SC bit cleared in ecap register?
I guess not, so it's probably only the problem of vIOMMU.
But then what does the code mean above?
If SC is required for scalable mode, ecap_sc_support()==false already implies sm_supported()==false too. Then that check seems redundant.
Quoted 17 lines
Quoted 3 lines
That sounds odd, and not sure why. Maybe Yi
Liu or Yi Sun may know?Another interesting point is that, it looks to me after that commit SNP is used for the domain that is not UNMANAGED even if PGSNP is not set.
Quoted 7 lines
Quoted 4 lines
To unbreak the guest, ignore the SNP bit for scalable mode first. In the future we may consider to add SC support.
Oh yes, I remembered the last time we discussed this. Could you remind me what's missing for us to support SC?
Quoted 8 lines
Exactly what you described below.
Quoted 2 lines
IIUC, for common device emulations we can just declare SC==1, right?
Strictly speaking, only safe for the datapath that is running in the Qemu. For things like vhost-user, I'm not sure it can check CC when using VFIO.
Hmm yeah.. though I'll just call those vhost-user backends to fall into below "device assignment" category too. Great to know we're on the same page here.
Quoted 17 lines
Quoted 10 lines
As all
the DMAs (including kernel accels like vhost) will be from host processors so there're no coherent issues with guest vcpu threads.If that's correct, the only challenge is device assignment in any form (I am not familiar with vdpa; so perhaps that includes vfio, vpda and any other kind of assigning host devices to guest?), then we'll try to detect
IOMMU_CACHEcapability from the host iommu groups that covers the assigned devices, and we only set SC==1 if we have cache coherency on all the devices?For VFIO yes, and we should prevent VFIO without CC to be plugged if SC is advertised.
For vDPA, we don't need to worry about it at all, kernel vDPA forces
IOMMU_CACHEnow.
Quoted 7 lines
vhost_vdpa_alloc_domain():if (!iommu_capable(bus,
IOMMU_CAP_CACHE_COHERENCY))
return-ENOTSUPP;(For device with on-chip IOMMU, it's the parent and device that guarantees the CC)
Ah right, yes you mentioned it and I forgot.. Though I'm not sure we'd simply double-check again here (if we'll support vfio anyway, then we'll need to be able to read those out from IOMMU groups), because we shouldn't rely on that fact which is an implementation detail of vdpa, imho (say, when vdpa starts to support !SC someday).
PS: I have other comments below in previous reply - please have a look too! :-D
Quoted 46 lines
Thanks
Quoted 42 lines
Quoted 23 lines
Signed-off-by Jason Wang <[email protected]>--- hw/i386/intel_iommu.c | 18 ++++++++++++------ hw/i386/intel_iommu_internal.h | 2 ++ 2 files changed, 14 insertions(+), 6 deletions(-)hw/i386/intel_iommu.c +2
-1@@ -969,7 +969,8 @@ static dma_addr_t vtd_get_iova_pgtbl_base(IntelIOMMUState *s,static uint64_t vtd_spte_rsvd[5 ];static uint64_t vtd_spte_rsvd_large[5 ]; -static bool vtd_slpte_nonzero_rsvd (uint64_t slpte,uint32_t level) +static bool vtd_slpte_nonzero_rsvd (IntelIOMMUState *s, +uint64_t slpte,uint32_t level) {uint64_t rsvd_mask = vtd_spte_rsvd[level];hw/i386/intel_iommu.c static bool vtd_slpte_nonzero_rsvd(uint64_t slpte, uint32_t level) · line 985
Quoted 6 lines
hw/i386/intel_iommu.c +3
-0@@ -979,6 +980,10 @@ static bool vtd_slpte_nonzero_rsvd(uint64_t slpte, uint32_t level) rsvd_mask = vtd_spte_rsvd_large[level]; } +if (s->scalable_mode) { + rsvd_mask &= ~VTD_SPTE_SNP ; + }IMHO what we want to do is only to skip the leaves of pgtables on SNP, so maybe we still want to keep checking the bit 11 reserved for e.g. common pgtable dir entries?
To do so, how about directly modifying the vtd_spte_rsvd* fields in
vtd_init()? I think we only need to modify 4k/2m/1g entries to mask bit 11, they're:- vtd_spte_rsvd[1] (4K)
- vtd_spte_rsvd_large[2] (2M)
- vtd_spte_rsvd_large[3] (1G)What do you think? Then we avoid passing IntelIOMMUState* all over too.
[Here]
Quoted 72 lines
Quoted 71 lines
Quoted 65 lines
hw/i386/intel_iommu.c +7
-5+return slpte & rsvd_mask; }@@ -1054,7 +1059,7 @@ static int vtd_iova_to_slpte(IntelIOMMUState *s, VTDContextEntry *ce, iova, level, slpte, is_write);return is_write ? -VTD_FR_WRITE : -VTD_FR_READ ; } -if (vtd_slpte_nonzero_rsvd (slpte, level)) { +if (vtd_slpte_nonzero_rsvd (s, slpte, level)) { error_report_once("%s: detected splte reserve non-zero " "iova=0x%" PRIx64 ", level=0x%" PRIx32 "slpte=0x%" PRIx64 ")", __func__, iova,@@ -1185,7 +1190,8 @@ static int vtd_page_walk_one(IOMMUTLBEvent *event, vtd_page_walk_info *info)* @write: whether parent level has write permission * @info: constant information for the page walk */ -static int vtd_page_walk_level (dma_addr_t addr,uint64_t start, +static int vtd_page_walk_level (IntelIOMMUState *s, +dma_addr_t addr,uint64_t start,uint64_t end,uint32_t level,bool read,bool write,vtd_page_walk_info *info) {@@ -1214,7 +1220,7 @@ static int vtd_page_walk_level(dma_addr_t addr, uint64_t start, goto next; } -if (vtd_slpte_nonzero_rsvd (slpte, level)) { +if (vtd_slpte_nonzero_rsvd (s, slpte, level)) {trace_vtd_page_walk_skip_reserve (iova, iova_next); goto next; }@@ -1235,7 +1241,7 @@ static int vtd_page_walk_level(dma_addr_t addr, uint64_t start,* This is a valid PDE (or even bigger than PDE). We need * to walk one further level. */ - ret =vtd_page_walk_level (vtd_get_slpte_addr (slpte, info->aw), + ret =vtd_page_walk_level (s,vtd_get_slpte_addr (slpte, info->aw), iova,MIN (iova_next, end), level -1 , read_cur, write_cur, info); }else {@@ -1294,7 +1300,7 @@ static int vtd_page_walk(IntelIOMMUState *s, VTDContextEntry *ce, end =vtd_iova_limit (s, ce, info->aw); } -return vtd_page_walk_level (addr, start, end, level, true, true, info); +return vtd_page_walk_level (s, addr, start, end, level, true, true, info); } static int vtd_root_entry_rsvd_bits_check(IntelIOMMUState *s,hw/i386/intel_iommu_internal.h +2
-1@@ -388,6 +388,8 @@ typedef union VTDInvDesc VTDInvDesc;#define VTD_INV_DESC_DEVICE_IOTLB_RSVD_LO 0xffff0000ffe0fff8/* Rsvd field masks for spte */ +#define VTD_SPTE_SNP 0x800ULL +#define VTD_SPTE_PAGE_L1_RSVD_MASK (aw, dt_supported) \ dt_supported ? \ (0x800ULL | ~(VTD_HAW_MASK(aw) | VTD_SL_IGN_COM | VTD_SL_TM)) : \ --Quoted 2 lines
2.25.1
--
Peter Xu
Signature · 1 line
Peter Xu
Quoted 42 lines · Peter Xu
Quoted 40 lines · Jason Wang
Quoted 39 lines · Peter Xu
Quoted 11 lines · Jason Wang
When booting with scalable mode, I hit this error:
qemu-system-x86_64:
vtd_iova_to_slpte: detected splte reserve non-zero iova=0xfffff002, level=0x1slpte=0x102681803)
qemu-system-x86_64:vtd_iommu_translate: detected translation failure (dev=01:00:00, iova=0xfffff002)
qemu-system-x86_64: New fault is not recorded due to compression of faultsThis is because the SNP bit is set since Linux kernel commit
6c00612d0cba1("iommu/vt-d: Report right snoop capability when using FL for IOVA") where SNP bit is set if scalable mode is on though this seems to be an violation on the spec which said the SNP bit is considered to be reserved if SC is not supported.When I was reading that commit, I was actually confused by this change:
---8<---
drivers/iommu/intel/iommu.c +8
-2@@ -658,7 +658,14 @@ static int domain_update_iommu_snooping(struct intel_iommu *skip)rcu_read_lock ();for_each_active_iommu (iommu, drhd) {if (iommu != skip) { -if (!ecap_sc_support (iommu->ecap)) { +/* +* If the hardware is operating in the scalable mode, +* the snooping control is always supported since we +* always set PASID-table-entry.PGSNP bit if the domain +* is managed outside (UNMANAGED). +*/ +if (!sm_supported (iommu) && + !ecap_sc_support (iommu->ecap)) { ret =0 ;break ; } ---8<---
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Does it mean that for some hardwares that has sm_supported()==true, it'll have SC bit cleared in ecap register?
I guess not, so it's probably only the problem of vIOMMU.
But then what does the code mean above?
If SC is required for scalable mode,
I guess the code was tested on hardware with both SC and SM.
Quoted 2 lines
ecap_sc_support()==false already implies sm_supported()==false too. Then that check seems redundant.
To tell the truth, I'm not sure. And according to the spec SNP is reserved if SC==false.
Quoted 21 lines
Quoted 21 lines
Quoted 4 lines
That sounds odd, and not sure why. Maybe Yi
Liu or Yi Sun may know?Another interesting point is that, it looks to me after that commit SNP is used for the domain that is not UNMANAGED even if PGSNP is not set.
Quoted 7 lines
Quoted 4 lines
To unbreak the guest, ignore the SNP bit for scalable mode first. In the future we may consider to add SC support.
Oh yes, I remembered the last time we discussed this. Could you remind me what's missing for us to support SC?
Exactly what you described below.
Quoted 1 line
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
IIUC, for common device emulations we can just declare SC==1, right?
Strictly speaking, only safe for the datapath that is running in the Qemu. For things like vhost-user, I'm not sure it can check CC when using VFIO.
Hmm yeah.. though I'll just call those vhost-user backends to fall into below "device assignment" category too. Great to know we're on the same page here.
I see.
Quoted 23 lines
Quoted 23 lines
Quoted 11 lines
As all
the DMAs (including kernel accels like vhost) will be from host processors so there're no coherent issues with guest vcpu threads.If that's correct, the only challenge is device assignment in any form (I am not familiar with vdpa; so perhaps that includes vfio, vpda and any other kind of assigning host devices to guest?), then we'll try to detect
IOMMU_CACHEcapability from the host iommu groups that covers the assigned devices, and we only set SC==1 if we have cache coherency on all the devices?For VFIO yes, and we should prevent VFIO without CC to be plugged if SC is advertised.
For vDPA, we don't need to worry about it at all, kernel vDPA forces
IOMMU_CACHEnow.
vhost_vdpa_alloc_domain():if (!iommu_capable(bus,
IOMMU_CAP_CACHE_COHERENCY))
return-ENOTSUPP;
Quoted 8 lines
Quoted 2 lines
(For device with on-chip IOMMU, it's the parent and device that guarantees the CC)
Ah right, yes you mentioned it and I forgot.. Though I'm not sure we'd simply double-check again here (if we'll support vfio anyway, then we'll need to be able to read those out from IOMMU groups), because we shouldn't rely on that fact which is an implementation detail of vdpa, imho (say, when vdpa starts to support !SC someday).
Good point, but at that time we need to expose the !SC via uAPI which is currently not supported.
Quoted 2 lines
PS: I have other comments below in previous reply - please have a look too! :-D
Sorry for missing that part :(
Quoted 31 lines
Quoted 31 lines
Thanks
Quoted 26 lines
Quoted 26 lines
Signed-off-by Jason Wang <[email protected]>--- hw/i386/intel_iommu.c | 18 ++++++++++++------ hw/i386/intel_iommu_internal.h | 2 ++ 2 files changed, 14 insertions(+), 6 deletions(-)hw/i386/intel_iommu.c +2
-1@@ -969,7 +969,8 @@ static dma_addr_t vtd_get_iova_pgtbl_base(IntelIOMMUState *s,static uint64_t vtd_spte_rsvd[5 ];static uint64_t vtd_spte_rsvd_large[5 ]; -static bool vtd_slpte_nonzero_rsvd (uint64_t slpte,uint32_t level) +static bool vtd_slpte_nonzero_rsvd (IntelIOMMUState *s, +uint64_t slpte,uint32_t level) {uint64_t rsvd_mask = vtd_spte_rsvd[level];@@ -979,6 +980,10 @@ static bool vtd_slpte_nonzero_rsvd(uint64_t slpte, uint32_t level) rsvd_mask = vtd_spte_rsvd_large[level]; }
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
hw/i386/intel_iommu.c static bool vtd_slpte_nonzero_rsvd(uint64_t slpte, uint32_t level) · line 985
Quoted 3 lines
hw/i386/intel_iommu.c +3
-0+if (s->scalable_mode) { + rsvd_mask &= ~VTD_SPTE_SNP ; + }IMHO what we want to do is only to skip the leaves of pgtables on SNP, so maybe we still want to keep checking the bit 11 reserved for e.g. common pgtable dir entries?
Maybe, but it's probably a question that can only be answered by Intel. I can change it for the next version if you stick.
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
To do so, how about directly modifying the vtd_spte_rsvd* fields in
vtd_init()? I think we only need to modify 4k/2m/1g entries to mask bit 11, they're:- vtd_spte_rsvd[1] (4K)
- vtd_spte_rsvd_large[2] (2M)
- vtd_spte_rsvd_large[3] (1G)What do you think? Then we avoid passing IntelIOMMUState* all over too.
I started a version like that:), it should work, I will change that if it was agreed by everyone.
The reason that I changed to pass IntelIOMMUState is that it results in a smaller changeset. The reason is that I tend to introduce new rsvd bits for SM mode since after checking vtd 3.3 it looks have different reserved bit requirement than before (at least 1.2)
Thanks
Quoted 79 lines
[Here]
Quoted 58 lines
Quoted 58 lines
Quoted 58 lines
hw/i386/intel_iommu.c +7
-5+return slpte & rsvd_mask; }@@ -1054,7 +1059,7 @@ static int vtd_iova_to_slpte(IntelIOMMUState *s, VTDContextEntry *ce, iova, level, slpte, is_write);return is_write ? -VTD_FR_WRITE : -VTD_FR_READ ; } -if (vtd_slpte_nonzero_rsvd (slpte, level)) { +if (vtd_slpte_nonzero_rsvd (s, slpte, level)) { error_report_once("%s: detected splte reserve non-zero " "iova=0x%" PRIx64 ", level=0x%" PRIx32 "slpte=0x%" PRIx64 ")", __func__, iova,@@ -1185,7 +1190,8 @@ static int vtd_page_walk_one(IOMMUTLBEvent *event, vtd_page_walk_info *info)* @write: whether parent level has write permission * @info: constant information for the page walk */ -static int vtd_page_walk_level (dma_addr_t addr,uint64_t start, +static int vtd_page_walk_level (IntelIOMMUState *s, +dma_addr_t addr,uint64_t start,uint64_t end,uint32_t level,bool read,bool write,vtd_page_walk_info *info) {@@ -1214,7 +1220,7 @@ static int vtd_page_walk_level(dma_addr_t addr, uint64_t start, goto next; } -if (vtd_slpte_nonzero_rsvd (slpte, level)) { +if (vtd_slpte_nonzero_rsvd (s, slpte, level)) {trace_vtd_page_walk_skip_reserve (iova, iova_next); goto next; }@@ -1235,7 +1241,7 @@ static int vtd_page_walk_level(dma_addr_t addr, uint64_t start,* This is a valid PDE (or even bigger than PDE). We need * to walk one further level. */ - ret =vtd_page_walk_level (vtd_get_slpte_addr (slpte, info->aw), + ret =vtd_page_walk_level (s,vtd_get_slpte_addr (slpte, info->aw), iova,MIN (iova_next, end), level -1 , read_cur, write_cur, info); }else {@@ -1294,7 +1300,7 @@ static int vtd_page_walk(IntelIOMMUState *s, VTDContextEntry *ce, end =vtd_iova_limit (s, ce, info->aw); } -return vtd_page_walk_level (addr, start, end, level, true, true, info); +return vtd_page_walk_level (s, addr, start, end, level, true, true, info); } static int vtd_root_entry_rsvd_bits_check(IntelIOMMUState *s,hw/i386/intel_iommu_internal.h +0
-0@@ -388,6 +388,8 @@ typedef union VTDInvDesc VTDInvDesc;#define VTD_INV_DESC_DEVICE_IOTLB_RSVD_LO 0xffff0000ffe0fff8Quoted 14 lines
Quoted 4 lines
Quoted 4 lines
hw/i386/intel_iommu_internal.h +2
-0/* Rsvd field masks for spte */ +#define VTD_SPTE_SNP 0x800ULL +#define VTD_SPTE_PAGE_L1_RSVD_MASK (aw, dt_supported) \Quoted 9 lines
Quoted 5 lines
hw/i386/intel_iommu_internal.h +0
-1dt_supported ? \ (0x800ULL | ~(VTD_HAW_MASK(aw) | VTD_SL_IGN_COM | VTD_SL_TM)) : \ --2.25.1
--
Peter Xu--
Peter Xu
Quoted 18 lines · Jason Wang
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
(quoted diff) +2
-1-static bool vtd_slpte_nonzero_rsvd(uint64_t slpte, uint32_t level) +static bool vtd_slpte_nonzero_rsvd(IntelIOMMUState *s, + uint64_t slpte, uint32_t level) { uint64_t rsvd_mask = vtd_spte_rsvd[level];@@ -979,6 +980,10 @@ static bool vtd_slpte_nonzero_rsvd(uint64_t slpte, uint32_t level) rsvd_mask = vtd_spte_rsvd_large[level]; }Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Review static bool vtd_slpte_nonzero_rsvd(uint64_t slpte, uint32_t level) · line 985
Quoted 3 lines
(quoted diff) +3
-0+ if (s->scalable_mode) { + rsvd_mask &= ~VTD_SPTE_SNP; + }IMHO what we want to do is only to skip the leaves of pgtables on SNP, so maybe we still want to keep checking the bit 11 reserved for e.g. common pgtable dir entries?
Quoted 2 lines
Maybe, but it's probably a question that can only be answered by Intel. I can change it for the next version if you stick.
I'm reading vtd spec v3.1 (June 2019) here, and chap 9.8 told me they're reserved bits for pgdir entries, as no SNP bit defined on pgdir entries.
Quoted 11 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
To do so, how about directly modifying the vtd_spte_rsvd* fields in
vtd_init()? I think we only need to modify 4k/2m/1g entries to mask bit 11, they're:- vtd_spte_rsvd[1] (4K)
- vtd_spte_rsvd_large[2] (2M)
- vtd_spte_rsvd_large[3] (1G)What do you think? Then we avoid passing IntelIOMMUState* all over too.
Quoted 7 lines
I started a version like that:), it should work, I will change that if it was agreed by everyone.
The reason that I changed to pass IntelIOMMUState is that it results in a smaller changeset. The reason is that I tend to introduce new rsvd bits for SM mode since after checking vtd 3.3 it looks have different reserved bit requirement than before (at least 1.2)
Oh I thought changing vtd_spte_rsvd* should have smaller changeset instead, hmm? :)
IMHO it'll be:
if (s->scalable_mode) {
vtd_spte_rsvd[1] &= ~BIT(11);
vtd_spte_rsvd_large[2] &= ~BIT(11);
vtd_spte_rsvd_large[3] &= ~BIT(11);
}Would that work? Thanks,
Signature · 1 line
Peter Xu
Quoted 20 lines · Peter Xu
Quoted 18 lines · Jason Wang
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Review static bool vtd_slpte_nonzero_rsvd(uint64_t slpte, uint32_t level) · line 985
Quoted 13 lines
(quoted diff) +5
-1-static bool vtd_slpte_nonzero_rsvd(uint64_t slpte, uint32_t level) +static bool vtd_slpte_nonzero_rsvd(IntelIOMMUState *s, + uint64_t slpte, uint32_t level) { uint64_t rsvd_mask = vtd_spte_rsvd[level];@@ -979,6 +980,10 @@ static bool vtd_slpte_nonzero_rsvd(uint64_t slpte, uint32_t level) rsvd_mask = vtd_spte_rsvd_large[level]; } + if (s->scalable_mode) { + rsvd_mask &= ~VTD_SPTE_SNP; + }IMHO what we want to do is only to skip the leaves of pgtables on SNP, so maybe we still want to keep checking the bit 11 reserved for e.g. common pgtable dir entries?
Quoted 5 lines
Quoted 2 lines
Maybe, but it's probably a question that can only be answered by Intel. I can change it for the next version if you stick.
I'm reading vtd spec v3.1 (June 2019) here, and chap 9.8 told me they're reserved bits for pgdir entries, as no SNP bit defined on pgdir entries.
Yes, you're right.
Quoted 25 lines
Quoted 12 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
To do so, how about directly modifying the vtd_spte_rsvd* fields in
vtd_init()? I think we only need to modify 4k/2m/1g entries to mask bit 11, they're:- vtd_spte_rsvd[1] (4K)
- vtd_spte_rsvd_large[2] (2M)
- vtd_spte_rsvd_large[3] (1G)What do you think? Then we avoid passing IntelIOMMUState* all over too.
Quoted 7 lines
I started a version like that:), it should work, I will change that if it was agreed by everyone.
The reason that I changed to pass IntelIOMMUState is that it results in a smaller changeset. The reason is that I tend to introduce new rsvd bits for SM mode since after checking vtd 3.3 it looks have different reserved bit requirement than before (at least 1.2)
Oh I thought changing vtd_spte_rsvd* should have smaller changeset instead, hmm? :)
IMHO it'll be:
Quoted 7 lines
if (s->scalable_mode) { vtd_spte_rsvd[1] &= ~BIT(11); vtd_spte_rsvd_large[2] &= ~BIT(11); vtd_spte_rsvd_large[3] &= ~BIT(11); }Would that work? Thanks,
Works for sure, if we just want to fix the SNP bit.
(I actually have a version like this as well). I can go this way
The reason why I had another big changset is to align the reserved bits to vtd 3.3. E.g it equires e.g bit 62 to be reserved 63 to be ignored which seems not as strict as VTD_SL_IGN_COM. But it can be addressed in the future.
Thanks
Quoted 4 lines
--
Peter Xu
Quoted 60 lines · Jason Wang
Quoted 20 lines · Peter Xu
Quoted 18 lines · Jason Wang
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Review static bool vtd_slpte_nonzero_rsvd(uint64_t slpte, uint32_t level) · line 985
Quoted 13 lines
(quoted diff) +5
-1-static bool vtd_slpte_nonzero_rsvd(uint64_t slpte, uint32_t level) +static bool vtd_slpte_nonzero_rsvd(IntelIOMMUState *s, + uint64_t slpte, uint32_t level) { uint64_t rsvd_mask = vtd_spte_rsvd[level];@@ -979,6 +980,10 @@ static bool vtd_slpte_nonzero_rsvd(uint64_t slpte, uint32_t level) rsvd_mask = vtd_spte_rsvd_large[level]; } + if (s->scalable_mode) { + rsvd_mask &= ~VTD_SPTE_SNP; + }IMHO what we want to do is only to skip the leaves of pgtables on SNP, so maybe we still want to keep checking the bit 11 reserved for e.g. common pgtable dir entries?
Quoted 5 lines
Quoted 2 lines
Maybe, but it's probably a question that can only be answered by Intel. I can change it for the next version if you stick.
I'm reading vtd spec v3.1 (June 2019) here, and chap 9.8 told me they're reserved bits for pgdir entries, as no SNP bit defined on pgdir entries.
Yes, you're right.
Quoted 31 lines
Quoted 12 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
To do so, how about directly modifying the vtd_spte_rsvd* fields in
vtd_init()? I think we only need to modify 4k/2m/1g entries to mask bit 11, they're:- vtd_spte_rsvd[1] (4K)
- vtd_spte_rsvd_large[2] (2M)
- vtd_spte_rsvd_large[3] (1G)What do you think? Then we avoid passing IntelIOMMUState* all over too.
Quoted 7 lines
I started a version like that:), it should work, I will change that if it was agreed by everyone.
The reason that I changed to pass IntelIOMMUState is that it results in a smaller changeset. The reason is that I tend to introduce new rsvd bits for SM mode since after checking vtd 3.3 it looks have different reserved bit requirement than before (at least 1.2)
Oh I thought changing vtd_spte_rsvd* should have smaller changeset instead, hmm? :)
IMHO it'll be:
if (s->scalable_mode) { vtd_spte_rsvd[1] &= ~BIT(11); vtd_spte_rsvd_large[2] &= ~BIT(11); vtd_spte_rsvd_large[3] &= ~BIT(11); }
Quoted 5 lines
Quoted 1 line
Would that work? Thanks,
Works for sure, if we just want to fix the SNP bit.
(I actually have a version like this as well). I can go this way
Sounds good at least to me. Thanks!
Quoted 5 lines
The reason why I had another big changset is to align the reserved bits to vtd 3.3. E.g it equires e.g bit 62 to be reserved 63 to be ignored which seems not as strict as
VTD_SL_IGN_COM. But it can be addressed in the future.
Ah I see. We can do that later, or if the patch is ready anway IMHO we can have them fixed altogether too.
It's weird that VT-d spec seems to be very prone to changes.. that's rare as a spec, and it even happened multiple times.
Another trivial thing: for that SNP bit code change, shall we also reference the Linux commit 6c00612d0cba ("iommu/vt-d: Report right snoop capability when using FL for IOVA", 2021-04-07) directly in the code as comment? Just want to make sure we'll never forget why we added it as no one will be able to find a clue in the spec, meanwhile that explicit hint let us remember when we added SC support we can drop it.
Signature · 1 line
Peter Xu
Quoted 76 lines · Peter Xu
Quoted 60 lines · Jason Wang
Quoted 20 lines · Peter Xu
Quoted 18 lines · Jason Wang
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Review static bool vtd_slpte_nonzero_rsvd(uint64_t slpte, uint32_t level) · line 985
Quoted 13 lines
(quoted diff) +5
-1-static bool vtd_slpte_nonzero_rsvd(uint64_t slpte, uint32_t level) +static bool vtd_slpte_nonzero_rsvd(IntelIOMMUState *s, + uint64_t slpte, uint32_t level) { uint64_t rsvd_mask = vtd_spte_rsvd[level];@@ -979,6 +980,10 @@ static bool vtd_slpte_nonzero_rsvd(uint64_t slpte, uint32_t level) rsvd_mask = vtd_spte_rsvd_large[level]; } + if (s->scalable_mode) { + rsvd_mask &= ~VTD_SPTE_SNP; + }IMHO what we want to do is only to skip the leaves of pgtables on SNP, so maybe we still want to keep checking the bit 11 reserved for e.g. common pgtable dir entries?
Quoted 5 lines
Quoted 2 lines
Maybe, but it's probably a question that can only be answered by Intel. I can change it for the next version if you stick.
I'm reading vtd spec v3.1 (June 2019) here, and chap 9.8 told me they're reserved bits for pgdir entries, as no SNP bit defined on pgdir entries.
Yes, you're right.
Quoted 31 lines
Quoted 12 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
To do so, how about directly modifying the vtd_spte_rsvd* fields in
vtd_init()? I think we only need to modify 4k/2m/1g entries to mask bit 11, they're:- vtd_spte_rsvd[1] (4K)
- vtd_spte_rsvd_large[2] (2M)
- vtd_spte_rsvd_large[3] (1G)What do you think? Then we avoid passing IntelIOMMUState* all over too.
Quoted 7 lines
I started a version like that:), it should work, I will change that if it was agreed by everyone.
The reason that I changed to pass IntelIOMMUState is that it results in a smaller changeset. The reason is that I tend to introduce new rsvd bits for SM mode since after checking vtd 3.3 it looks have different reserved bit requirement than before (at least 1.2)
Oh I thought changing vtd_spte_rsvd* should have smaller changeset instead, hmm? :)
IMHO it'll be:
if (s->scalable_mode) { vtd_spte_rsvd[1] &= ~BIT(11); vtd_spte_rsvd_large[2] &= ~BIT(11); vtd_spte_rsvd_large[3] &= ~BIT(11); }Quoted 5 lines
Quoted 1 line
Would that work? Thanks,
Works for sure, if we just want to fix the SNP bit.
(I actually have a version like this as well). I can go this way
Sounds good at least to me. Thanks!
Quoted 5 lines
The reason why I had another big changset is to align the reserved bits to vtd 3.3. E.g it equires e.g bit 62 to be reserved 63 to be ignored which seems not as strict as
VTD_SL_IGN_COM. But it can be addressed in the future.
Quoted 5 lines
Ah I see. We can do that later, or if the patch is ready anway IMHO we can have them fixed altogether too.
It's weird that VT-d spec seems to be very prone to changes.. that's rare as a spec, and it even happened multiple times.
A side-effect is to bring troubles for the migration compatibility :(
Quoted 7 lines
Another trivial thing: for that SNP bit code change, shall we also reference the Linux commit
6c00612d0cba("iommu/vt-d: Report right snoop capability when using FL for IOVA", 2021-04-07) directly in the code as comment? Just want to make sure we'll never forget why we added it as no one will be able to find a clue in the spec, meanwhile that explicit hint let us remember when we added SC support we can drop it.
Adding BaoLu.
As discussed, according to my test with vIOMMU, there are side effect of that commit which uses SNP even for the second level page table for domains that is not IOMMU_DOMAIN_UNMANAGED. If I was wrong, we can refer to that in the code.
Thanks
Quoted 4 lines
--
Peter Xu
Quoted 28 lines
From: Jason Wang <[email protected]>
Sent: Wednesday, November 24, 2021 5:35 PMQuoted 3 lines · Peter Xu
Quoted 1 line · Jason Wang
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
-static bool vtd_slpte_nonzero_rsvd(uint64_t slpte,
uint32_tlevel)
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Review static bool
Quoted 6 lines
(quoted diff) +2
-0+static bool vtd_slpte_nonzero_rsvd(IntelIOMMUState *s, + uint64_t slpte, uint32_t level) { uint64_t rsvd_mask = vtd_spte_rsvd[level];@@ -979,6 +980,10 @@ static bool
vtd_slpte_nonzero_rsvd(uint64_t slpte, uint32_t level)Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Review static bool · line 985
Quoted 6 lines
(quoted diff) +3
-0rsvd_mask = vtd_spte_rsvd_large[level]; } + if (s->scalable_mode) { + rsvd_mask &= ~VTD_SPTE_SNP; + }IMHO what we want to do is only to skip the leaves of pgtables on
SNP, so maybe
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
we still want to keep checking the bit 11 reserved for e.g. common
pgtable dir
Quoted 2 lines
Quoted 2 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
entries?
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Maybe, but it's probably a question that can only be answered by Intel. I can change it for the next version if you stick.
I'm reading vtd spec v3.1 (June 2019) here, and chap 9.8 told me they're reserved bits for pgdir entries, as no SNP bit defined on pgdir entries.
Yes, you're right.
yeah. The SNP bit is only available in the leaf paging entry. e.g. for 4KB pages, the SNP bit is in the PTE, but for 2MB pages, the SNP bit is in PDE, and etc.
Regards,
Yi Liu
Quoted 51 lines
From: Jason Wang <[email protected]>
Sent: Wednesday, November 24, 2021 4:29 PMQuoted 5 lines · Peter Xu
Quoted 3 lines · Jason Wang
When booting with scalable mode, I hit this error:
qemu-system-x86_64:
vtd_iova_to_slpte: detected splte reserve non-zero iova=0xfffff002, level=0x1slpte=0x102681803)
Quoted 1 line
Quoted 1 line
qemu-system-x86_64:
vtd_iommu_translate: detected translationfailure (dev=01:00:00, iova=0xfffff002)
Quoted 1 line
Quoted 1 line
qemu-system-x86_64: New fault is not recorded due to compression of
faults
drivers/iommu/intel/iommu.c static int
Quoted 15 lines
Quoted 6 lines
This is because the SNP bit is set since Linux kernel commit
6c00612d0cba1("iommu/vt-d: Report right snoop capability when using FL for IOVA") where SNP bit is set if scalable mode is on though this seems to be an violation on the spec which said the SNP bit is considered to be reserved if SC is not supported.When I was reading that commit, I was actually confused by this change:
---8<---
drivers/iommu/intel/iommu.c +0
-0@@ -658,7 +658,14 @@ static int
domain_update_iommu_snooping(struct intel_iommu *skip)Quoted 17 lines
drivers/iommu/intel/iommu.c +8
-2rcu_read_lock ();for_each_active_iommu (iommu, drhd) {if (iommu != skip) { -if (!ecap_sc_support (iommu->ecap)) { +/* +* If the hardware is operating in the scalable mode, +* the snooping control is always supported since we +* always set PASID-table-entry.PGSNP bit if the domain +* is managed outside (UNMANAGED). +*/ +if (!sm_supported (iommu) && + !ecap_sc_support (iommu->ecap)) { ret =0 ;break ; } ---8<---Quoted 1 line
Does it mean that for some hardwares that has sm_supported()==true,
it'll have
Quoted 1 line
SC bit cleared in ecap register?
Quoted 8 lines
I guess not, so it's probably only the problem of vIOMMU.
Quoted 2 lines
That sounds odd, and not sure why. Maybe Yi
Liu or Yi Sun may know?Another interesting point is that, it looks to me after that commit SNP is used for the domain that is not UNMANAGED even if PGSNP is not set.
Per spec, if the PGSNP is set, it means the final page access is snooped. If it's not set, then it's up to other bit to decide it. For detail, you may refer to table 6 of chapter 3.9 in vtd 3.2 spec.
Regards,
Yi Liu
Quoted 43 lines
From: Peter Xu <[email protected]>
Sent: Wednesday, November 24, 2021 3:57 PMQuoted 3 lines · Jason Wang
When booting with scalable mode, I hit this error:
qemu-system-x86_64:
vtd_iova_to_slpte: detected splte reserve non-zero iova=0xfffff002, level=0x1slpte=0x102681803)
Quoted 1 line
qemu-system-x86_64:
vtd_iommu_translate: detected translation failure(dev=01:00:00, iova=0xfffff002)
Quoted 1 line
qemu-system-x86_64: New fault is not recorded due to compression of
faults
Quoted 6 lines
This is because the SNP bit is set since Linux kernel commit
6c00612d0cba1("iommu/vt-d: Report right snoop capability when using FL for IOVA") where SNP bit is set if scalable mode is on though this seems to be an violation on the spec which said the SNP bit is considered to be reserved if SC is not supported.When I was reading that commit, I was actually confused by this change:
---8<---
drivers/iommu/intel/iommu.c +8
-1@@ -658,7 +658,14 @@ static int domain_update_iommu_snooping(struct intel_iommu *skip)rcu_read_lock ();for_each_active_iommu (iommu, drhd) {if (iommu != skip) { -if (!ecap_sc_support (iommu->ecap)) { +/* +* If the hardware is operating in the scalable mode, +* the snooping control is always supported since we +* always set PASID-table-entry.PGSNP bit if the domain +* is managed outside (UNMANAGED). +*/ +if (!sm_supported (iommu) && + !ecap_sc_support (iommu->ecap)) { ret =0 ;break ;}
Quoted 5 lines
---8<---
Does it mean that for some hardwares that has sm_supported()==true, it'll have SC bit cleared in ecap register? That sounds odd, and not sure why. Maybe Yi Liu or Yi Sun may know?
scalable mode has no dependency on SC, so it's possible.
Quoted 11 lines
Quoted 3 lines
To unbreak the guest, ignore the SNP bit for scalable mode first. In the future we may consider to add SC support.
Oh yes, I remembered the last time we discussed this. Could you remind me what's missing for us to support SC?
IIUC, for common device emulations we can just declare SC==1, right? As all the DMAs (including kernel accels like vhost) will be from host processors so there're no coherent issues with guest vcpu threads.
Quoted 5 lines
If that's correct, the only challenge is device assignment in any form (I am not familiar with vdpa; so perhaps that includes vfio, vpda and any other kind of assigning host devices to guest?), then we'll try to detect
IOMMU_CACHEcapability from the host iommu groups that covers the assigned devices, and we only set SC==1 if we have cache coherency on all the devices?
above looks good to me. SC bit means SNP field available in leaf paging structure. So we need to check the host side's SC capability for the assigned devices, then decide whether set SC or not. Then guest iommu driver can set the SNP bit per its policy.
btw. there is a discussion on the IOMMU_CACHE, it's considered to be an incorrect usage to let it linked with no_snoop. So there may be some cleanup later. anyhow, just let you two be aware of it.
https://lore.kernel.org/kvm/[email protected]/
Regards,
Yi Liu
Quoted 124 lines
hw/i386/intel_iommu.c static dma_addr_t
Quoted 13 lines
Signed-off-by Jason Wang <[email protected]>--- hw/i386/intel_iommu.c | 18 ++++++++++++------ hw/i386/intel_iommu_internal.h | 2 ++ 2 files changed, 14 insertions(+), 6 deletions(-)hw/i386/intel_iommu.c +0
-0@@ -969,7 +969,8 @@ static dma_addr_tvtd_get_iova_pgtbl_base(IntelIOMMUState *s,
hw/i386/intel_iommu.c static bool vtd_slpte_nonzero_rsvd(uint64_t slpte,
Quoted 10 lines
hw/i386/intel_iommu.c +2
-1static uint64_t vtd_spte_rsvd[5 ];static uint64_t vtd_spte_rsvd_large[5 ]; -static bool vtd_slpte_nonzero_rsvd (uint64_t slpte,uint32_t level) +static bool vtd_slpte_nonzero_rsvd (IntelIOMMUState *s, +uint64_t slpte,uint32_t level) {uint64_t rsvd_mask = vtd_spte_rsvd[level];@@ -979,6 +980,10 @@ static bool vtd_slpte_nonzero_rsvd(uint64_t slpte,
uint32_tlevel)hw/i386/intel_iommu.c static bool vtd_slpte_nonzero_rsvd(uint64_t slpte, · line 985
Quoted 6 lines
hw/i386/intel_iommu.c +3
-0rsvd_mask = vtd_spte_rsvd_large[level]; } +if (s->scalable_mode) { + rsvd_mask &= ~VTD_SPTE_SNP ; + }IMHO what we want to do is only to skip the leaves of pgtables on SNP, so maybe
we still want to keep checking the bit 11 reserved for e.g. common pgtable dir
entries?To do so, how about directly modifying the vtd_spte_rsvd* fields in
vtd_init()?
I think we only need to modify 4k/2m/1g entries to mask bit 11, they're:- vtd_spte_rsvd[1] (4K)
- vtd_spte_rsvd_large[2] (2M)
- vtd_spte_rsvd_large[3] (1G)What do you think? Then we avoid passing IntelIOMMUState* all over too.
hw/i386/intel_iommu.c static int vtd_iova_to_slpte(IntelIOMMUState *s,
Quoted 5 lines
hw/i386/intel_iommu.c +1
-0+return slpte & rsvd_mask; }@@ -1054,7 +1059,7 @@ static int vtd_iova_to_slpte(IntelIOMMUState *s,VTDContextEntry *ce,
hw/i386/intel_iommu.c static int vtd_page_walk_one(IOMMUTLBEvent
Quoted 9 lines
hw/i386/intel_iommu.c +1
-1iova, level, slpte, is_write);return is_write ? -VTD_FR_WRITE : -VTD_FR_READ ; } -if (vtd_slpte_nonzero_rsvd (slpte, level)) { +if (vtd_slpte_nonzero_rsvd (s, slpte, level)) { error_report_once("%s: detected splte reserve non-zero " "iova=0x%" PRIx64 ", level=0x%" PRIx32 "slpte=0x%" PRIx64 ")", __func__, iova,@@ -1185,7 +1190,8 @@ static int vtd_page_walk_one(IOMMUTLBEvent*event,
vtd_page_walk_info*info)hw/i386/intel_iommu.c static int vtd_page_walk_level(dma_addr_t addr,
Quoted 10 lines
hw/i386/intel_iommu.c +2
-1* @write: whether parent level has write permission * @info: constant information for the page walk */ -static int vtd_page_walk_level (dma_addr_t addr,uint64_t start, +static int vtd_page_walk_level (IntelIOMMUState *s, +dma_addr_t addr,uint64_t start,uint64_t end,uint32_t level,bool read,bool write,vtd_page_walk_info *info) {@@ -1214,7 +1220,7 @@ static int vtd_page_walk_level(dma_addr_t addr,
uint64_tstart,hw/i386/intel_iommu.c static int vtd_page_walk_level(dma_addr_t addr,
Quoted 9 lines
hw/i386/intel_iommu.c +1
-1goto next; } -if (vtd_slpte_nonzero_rsvd (slpte, level)) { +if (vtd_slpte_nonzero_rsvd (s, slpte, level)) {trace_vtd_page_walk_skip_reserve (iova, iova_next); goto next; }@@ -1235,7 +1241,7 @@ static int vtd_page_walk_level(dma_addr_t addr,
uint64_tstart,hw/i386/intel_iommu.c static int vtd_page_walk(IntelIOMMUState *s,
Quoted 9 lines
hw/i386/intel_iommu.c +1
-1* This is a valid PDE (or even bigger than PDE). We need * to walk one further level. */ - ret =vtd_page_walk_level (vtd_get_slpte_addr (slpte, info->aw), + ret =vtd_page_walk_level (s,vtd_get_slpte_addr (slpte, info->aw), iova,MIN (iova_next, end), level -1 , read_cur, write_cur, info); }else {@@ -1294,7 +1300,7 @@ static int vtd_page_walk(IntelIOMMUState *s,VTDContextEntry *ce,
Review
Quoted 9 lines
hw/i386/intel_iommu.c +1
-1end =vtd_iova_limit (s, ce, info->aw); } -return vtd_page_walk_level (addr, start, end, level, true, true, info); +return vtd_page_walk_level (s, addr, start, end, level, true, true, info); } static int vtd_root_entry_rsvd_bits_check(IntelIOMMUState *s,(quoted diff) +0
-0
b/hw/i386/intel_iommu_internal.hhw/i386/intel_iommu_internal.h typedef union VTDInvDesc VTDInvDesc; · line 395
Quoted 12 lines
index
3d5487fe2c..a6c788049b100644hw/i386/intel_iommu_internal.h +2
-0@@ -388,6 +388,8 @@ typedef union VTDInvDesc VTDInvDesc;#define VTD_INV_DESC_DEVICE_IOTLB_RSVD_LO 0xffff0000ffe0fff8/* Rsvd field masks for spte */ +#define VTD_SPTE_SNP 0x800ULL +#define VTD_SPTE_PAGE_L1_RSVD_MASK (aw, dt_supported) \ dt_supported ? \ (0x800ULL | ~(VTD_HAW_MASK(aw) | VTD_SL_IGN_COM |
VTD_SL_TM)) : \Quoted 3 lines
--
2.25.1--
Peter Xu
Quoted 45 lines · Yi L
Quoted 45 lines
From: Peter Xu <[email protected]>
Sent: Wednesday, November 24, 2021 3:57 PMQuoted 3 lines · Jason Wang
When booting with scalable mode, I hit this error:
qemu-system-x86_64:
vtd_iova_to_slpte: detected splte reserve non-zero iova=0xfffff002, level=0x1slpte=0x102681803)
Quoted 1 line
qemu-system-x86_64:
vtd_iommu_translate: detected translation failure(dev=01:00:00, iova=0xfffff002)
Quoted 1 line
qemu-system-x86_64: New fault is not recorded due to compression of
faults
Quoted 6 lines
This is because the SNP bit is set since Linux kernel commit
6c00612d0cba1("iommu/vt-d: Report right snoop capability when using FL for IOVA") where SNP bit is set if scalable mode is on though this seems to be an violation on the spec which said the SNP bit is considered to be reserved if SC is not supported.When I was reading that commit, I was actually confused by this change:
---8<---
drivers/iommu/intel/iommu.c +8
-1@@ -658,7 +658,14 @@ static int domain_update_iommu_snooping(struct intel_iommu *skip)rcu_read_lock ();for_each_active_iommu (iommu, drhd) {if (iommu != skip) { -if (!ecap_sc_support (iommu->ecap)) { +/* +* If the hardware is operating in the scalable mode, +* the snooping control is always supported since we +* always set PASID-table-entry.PGSNP bit if the domain +* is managed outside (UNMANAGED). +*/ +if (!sm_supported (iommu) && + !ecap_sc_support (iommu->ecap)) { ret =0 ;break ;}---8<---
Quoted 5 lines
Quoted 3 lines
Does it mean that for some hardwares that has sm_supported()==true, it'll have SC bit cleared in ecap register? That sounds odd, and not sure why. Maybe Yi Liu or Yi Sun may know?
scalable mode has no dependency on SC, so it's possible.
I see; thanks, Yi.
However then OTOH I don't understand above comment
"If the hardware is operating in the scalable mode, the snooping control is
always supported since... "
Because the current qemu vt-d emulation should fall into the case that Yi mentioned - we support initial scalable mode but no SC yet..
Cc Baolu too.
Signature · 1 line
Peter Xu
Quoted 64 lines
From: Peter Xu <[email protected]>
Sent: Thursday, November 25, 2021 12:31 PMQuoted 9 lines · Yi L
Quoted 9 lines
From: Peter Xu <[email protected]>
Sent: Wednesday, November 24, 2021 3:57 PMQuoted 3 lines · Jason Wang
When booting with scalable mode, I hit this error:
qemu-system-x86_64:
vtd_iova_to_slpte: detected splte reserve non-zero iova=0xfffff002, level=0x1slpte=0x102681803)
Quoted 1 line
qemu-system-x86_64:
vtd_iommu_translate: detected translationfailure
Quoted 2 lines
Quoted 2 lines
(dev=01:00:00, iova=0xfffff002)
Quoted 1 line
qemu-system-x86_64: New fault is not recorded due to compression
of
Quoted 4 lines
Quoted 4 lines
faults
Quoted 3 lines
This is because the SNP bit is set since Linux kernel commit
6c00612d0cba1("iommu/vt-d: Report right snoop capability whenusing
Quoted 8 lines
Review
Quoted 8 lines
Quoted 3 lines
FL for IOVA") where SNP bit is set if scalable mode is on though this seems to be an violation on the spec which said the SNP bit is considered to be reserved if SC is not supported.
When I was reading that commit, I was actually confused by this change:
---8<---
(quoted diff) +0
-0
b/drivers/iommu/intel/iommu.cQuoted 4 lines
drivers/iommu/intel/iommu.c static int
Quoted 4 lines
index
956a02eb40b4..0ee5f1bd8af2100644drivers/iommu/intel/iommu.c +0
-0@@ -658,7 +658,14 @@ static intdomain_update_iommu_snooping(struct
Quoted 18 lines
Quoted 18 lines
drivers/iommu/intel/iommu.c +8
-1intel_iommu *skip)rcu_read_lock ();for_each_active_iommu (iommu, drhd) {if (iommu != skip) { -if (!ecap_sc_support (iommu->ecap)) { +/* +* If the hardware is operating in the scalable mode, +* the snooping control is always supported since we +* always set PASID-table-entry.PGSNP bit if the domain +* is managed outside (UNMANAGED). +*/ +if (!sm_supported (iommu) && + !ecap_sc_support (iommu->ecap)) { ret =0 ;break ;}---8<---
Quoted 1 line
Quoted 1 line
Does it mean that for some hardwares that has sm_supported()==true,
it'll
Quoted 1 line
Quoted 1 line
have SC bit cleared in ecap register? That sounds odd, and not sure why.
Maybe
Quoted 3 lines
Quoted 1 line
Yi Liu or Yi Sun may know?
scalable mode has no dependency on SC, so it's possible.
I see; thanks, Yi.
Quoted 7 lines
However then OTOH I don't understand above comment
"If the hardware is operating in the scalable mode, the snooping control is
always supported since... "Because the current qemu vt-d emulation should fall into the case that Yi mentioned - we support initial scalable mode but no SC yet..
chapter 3.9 of 3.2 spec says below.
“If the remapping hardware is setup in scalable-mode (RTADDR_REG.TTM=01b) and the Page Snoop (PGSNP) field in PASID-table entry is Set, access to the final page is snooped.”
It means the PGSNP field is available under scalable mode. And spec also says below in chapter 96. of 3.2 spec.
"Requests snoop processor caches irrespective of, other attributes in the request or other fields in paging structure entries used to translate the request."
It means the PGSNP field of PASID table entry is the first class control of the snoop behaviour. Also it means the scalable mode has the snoop control by default. ^_^. So the comment in the above commit is correct since the policy of intel iommu driver is always setting the PGSNP bit. But spec is not so clear. Will reach out to make it more clearer in the spec. thanks for catching it. :-)
Regards,
Yi Liu
Quoted 81 lines · Yi L
Quoted 64 lines
From: Peter Xu <[email protected]>
Sent: Thursday, November 25, 2021 12:31 PMQuoted 9 lines · Yi L
Quoted 9 lines
From: Peter Xu <[email protected]>
Sent: Wednesday, November 24, 2021 3:57 PMQuoted 3 lines · Jason Wang
When booting with scalable mode, I hit this error:
qemu-system-x86_64:
vtd_iova_to_slpte: detected splte reserve non-zero iova=0xfffff002, level=0x1slpte=0x102681803)
Quoted 1 line
qemu-system-x86_64:
vtd_iommu_translate: detected translationfailure
Quoted 2 lines
Quoted 2 lines
(dev=01:00:00, iova=0xfffff002)
Quoted 1 line
qemu-system-x86_64: New fault is not recorded due to compression
of
Quoted 4 lines
Quoted 4 lines
faults
Quoted 3 lines
This is because the SNP bit is set since Linux kernel commit
6c00612d0cba1("iommu/vt-d: Report right snoop capability whenusing
Quoted 8 lines
Review
Quoted 8 lines
Quoted 3 lines
FL for IOVA") where SNP bit is set if scalable mode is on though this seems to be an violation on the spec which said the SNP bit is considered to be reserved if SC is not supported.
When I was reading that commit, I was actually confused by this change:
---8<---
(quoted diff) +0
-0
b/drivers/iommu/intel/iommu.cQuoted 4 lines
drivers/iommu/intel/iommu.c static int
Quoted 4 lines
index
956a02eb40b4..0ee5f1bd8af2100644drivers/iommu/intel/iommu.c +0
-0@@ -658,7 +658,14 @@ static intdomain_update_iommu_snooping(struct
Quoted 18 lines
Quoted 18 lines
drivers/iommu/intel/iommu.c +8
-1intel_iommu *skip)rcu_read_lock ();for_each_active_iommu (iommu, drhd) {if (iommu != skip) { -if (!ecap_sc_support (iommu->ecap)) { +/* +* If the hardware is operating in the scalable mode, +* the snooping control is always supported since we +* always set PASID-table-entry.PGSNP bit if the domain +* is managed outside (UNMANAGED). +*/ +if (!sm_supported (iommu) && + !ecap_sc_support (iommu->ecap)) { ret =0 ;break ;}---8<---
Quoted 1 line
Quoted 1 line
Does it mean that for some hardwares that has sm_supported()==true,
it'll
Quoted 1 line
Quoted 1 line
have SC bit cleared in ecap register? That sounds odd, and not sure why.
Maybe
Quoted 3 lines
Quoted 1 line
Yi Liu or Yi Sun may know?
scalable mode has no dependency on SC, so it's possible.
I see; thanks, Yi.
Quoted 7 lines
However then OTOH I don't understand above comment
"If the hardware is operating in the scalable mode, the snooping control is
always supported since... "Because the current qemu vt-d emulation should fall into the case that Yi mentioned - we support initial scalable mode but no SC yet..
chapter 3.9 of 3.2 spec says below.
“If the remapping hardware is setup in scalable-mode (RTADDR_REG.TTM=01b) and the Page Snoop (PGSNP) field in PASID-table entry is Set, access to the final page is snooped.”
It means the PGSNP field is available under scalable mode. And spec also says below in chapter 96. of 3.2 spec.
Quoted 8 lines
"Requests snoop processor caches irrespective of, other attributes in the request or other fields in paging structure entries used to translate the request."
It means the PGSNP field of PASID table entry is the first class control of the snoop behaviour. Also it means the scalable mode has the snoop control by default. ^_^. So the comment in the above commit is correct since the policy of intel iommu driver is always setting the PGSNP bit.
I see. Setting PGSNP bit in the pasid entry looks fine to me.
However IIUC what's triggering the crash (that Jason is fixing) is the guest iommu driver "thinks" SC is supported since scalable is enabled (even if qemu vIOMMU has declared ECAP.SC==0 there), then it'll update iommu_snooping bit, then it'll try to attach the SNP bit in the 2nd level pgtable (intel_iommu_map):
if ((iommu_prot & IOMMU_CACHE) && dmar_domain->iommu_snooping) prot |= DMA_PTE_SNP;
So what I'm wondering is: whether the kernel should _not_ set SNP bit in the 2nd level pgtable, even if we set PGSNP in the pasid entry.. because as you mentioned, the hardware (here the emulated vIOMMU) is allowed to have both scalable==1 but sc==0 so it may recognize PGSNP in pasid entry but not the SNP bit in pgtables.
If we'll skip pgtable SNP bit anyway for scalable mode, it looks weird to explicitly set it too.
I think it's fine for Jason's solution to just skip checking SNP bit so we ignore it in qemu, however just to double check we're on the same page.
Thanks,
Signature · 1 line
Peter Xu
Quoted 104 lines
From: Peter Xu <[email protected]>
Sent: Thursday, November 25, 2021 2:14 PMQuoted 11 lines · Yi L
Quoted 11 lines
From: Peter Xu <[email protected]>
Sent: Thursday, November 25, 2021 12:31 PMQuoted 7 lines · Yi L
Quoted 7 lines
From: Peter Xu <[email protected]>
Sent: Wednesday, November 24, 2021 3:57 PMQuoted 3 lines · Jason Wang
When booting with scalable mode, I hit this error:
qemu-system-x86_64:
vtd_iova_to_slpte: detected splte reservenon-
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
zero iova=0xfffff002, level=0x1slpte=0x102681803)
Quoted 1 line
qemu-system-x86_64:
vtd_iommu_translate: detected translationfailure
Quoted 2 lines
Quoted 2 lines
(dev=01:00:00, iova=0xfffff002)
Quoted 1 line
qemu-system-x86_64: New fault is not recorded due to
compression
Quoted 11 lines
Quoted 11 lines
of
Quoted 4 lines
Quoted 4 lines
faults
Quoted 3 lines
This is because the SNP bit is set since Linux kernel commit
6c00612d0cba1("iommu/vt-d: Report right snoop capability whenusing
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
FL for IOVA") where SNP bit is set if scalable mode is on though this seems to be an violation on the spec which said the SNP bit is considered to be reserved if SC is not supported.
When I was reading that commit, I was actually confused by this
change:
Quoted 27 lines
Quoted 27 lines
Quoted 3 lines
Review
Quoted 3 lines
---8<---
(quoted diff) +0
-0
b/drivers/iommu/intel/iommu.cQuoted 4 lines
drivers/iommu/intel/iommu.c static int
Quoted 4 lines
index
956a02eb40b4..0ee5f1bd8af2100644drivers/iommu/intel/iommu.c +0
-0@@ -658,7 +658,14 @@ static intdomain_update_iommu_snooping(struct
Quoted 18 lines
Quoted 18 lines
drivers/iommu/intel/iommu.c +8
-1intel_iommu *skip)rcu_read_lock ();for_each_active_iommu (iommu, drhd) {if (iommu != skip) { -if (!ecap_sc_support (iommu->ecap)) { +/* +* If the hardware is operating in the scalable mode, +* the snooping control is always supported since we +* always set PASID-table-entry.PGSNP bit if the domain +* is managed outside (UNMANAGED). +*/ +if (!sm_supported (iommu) && + !ecap_sc_support (iommu->ecap)) { ret =0 ;break ;}---8<---
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Does it mean that for some hardwares that has
sm_supported()==true,
Quoted 2 lines
Quoted 2 lines
it'll
Quoted 1 line
Quoted 1 line
have SC bit cleared in ecap register? That sounds odd, and not sure
why.
Quoted 10 lines
Quoted 10 lines
Maybe
Quoted 3 lines
Quoted 1 line
Yi Liu or Yi Sun may know?
scalable mode has no dependency on SC, so it's possible.
I see; thanks, Yi.
However then OTOH I don't understand above comment
"If the hardware is operating in the scalable mode, the snooping control
is
Quoted 8 lines
Quoted 4 lines
always supported since... "
Because the current qemu vt-d emulation should fall into the case that Yi mentioned - we support initial scalable mode but no SC yet..
chapter 3.9 of 3.2 spec says below.
“If the remapping hardware is setup in scalable-mode
(RTADDR_REG.TTM=01b)
Quoted 1 line
and the Page Snoop (PGSNP) field in PASID-table entry is Set, access to
the
Quoted 5 lines
final page is snooped.”
It means the PGSNP field is available under scalable mode. And spec also says below in chapter 96. of 3.2 spec.
Quoted 8 lines
"Requests snoop processor caches irrespective of, other attributes in the request or other fields in paging structure entries used to translate the request."
It means the PGSNP field of PASID table entry is the first class control of the snoop behaviour. Also it means the scalable mode has the snoop control by default. ^_^. So the comment in the above commit is correct since the policy of intel iommu driver is always setting the PGSNP bit.
I see. Setting PGSNP bit in the pasid entry looks fine to me.
Quoted 9 lines
However IIUC what's triggering the crash (that Jason is fixing) is the guest iommu driver "thinks" SC is supported since scalable is enabled (even if qemu vIOMMU has declared ECAP.SC==0 there), then it'll update
iommu_snoopingbit, then it'll try to attach the SNP bit in the 2nd level pgtable (intel_iommu_map):if ((iommu_prot & IOMMU_CACHE) && dmar_domain->iommu_snooping) prot |= DMA_PTE_SNP;
Above is the fact today.
Quoted 5 lines
So what I'm wondering is: whether the kernel should _not_ set SNP bit in the 2nd level pgtable, even if we set PGSNP in the pasid entry.. because as you mentioned, the hardware (here the emulated vIOMMU) is allowed to have both scalable==1 but sc==0 so it may recognize PGSNP in pasid entry but not the SNP bit in pgtables.
This is a weird configuration. :( let's fix it in spec. e.g. PGSNP bit is supported only when scalable==1 and sc==1. this makes more sense. right? Then SNP bit will always depend on sc bit, it won't have any relationship with scalable bit.
Quoted 6 lines
If we'll skip pgtable SNP bit anyway for scalable mode, it looks weird to explicitly set it too.
I think it's fine for Jason's solution to just skip checking SNP bit so we ignore it in qemu, however just to double check we're on the same page.
If we have above fix in spec, the iommu driver would also update its behavior on the SNP bit. then the problem encountered by Jason will go away. right?
Thanks,
Yi Liu
Quoted 122 lines · Yi L
Quoted 104 lines
From: Peter Xu <[email protected]>
Sent: Thursday, November 25, 2021 2:14 PMQuoted 11 lines · Yi L
Quoted 11 lines
From: Peter Xu <[email protected]>
Sent: Thursday, November 25, 2021 12:31 PMQuoted 7 lines · Yi L
Quoted 7 lines
From: Peter Xu <[email protected]>
Sent: Wednesday, November 24, 2021 3:57 PMQuoted 3 lines · Jason Wang
When booting with scalable mode, I hit this error:
qemu-system-x86_64:
vtd_iova_to_slpte: detected splte reservenon-
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
zero iova=0xfffff002, level=0x1slpte=0x102681803)
Quoted 1 line
qemu-system-x86_64:
vtd_iommu_translate: detected translationfailure
Quoted 2 lines
Quoted 2 lines
(dev=01:00:00, iova=0xfffff002)
Quoted 1 line
qemu-system-x86_64: New fault is not recorded due to
compression
Quoted 11 lines
Quoted 11 lines
of
Quoted 4 lines
Quoted 4 lines
faults
Quoted 3 lines
This is because the SNP bit is set since Linux kernel commit
6c00612d0cba1("iommu/vt-d: Report right snoop capability whenusing
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
FL for IOVA") where SNP bit is set if scalable mode is on though this seems to be an violation on the spec which said the SNP bit is considered to be reserved if SC is not supported.
When I was reading that commit, I was actually confused by this
change:
Quoted 27 lines
Quoted 27 lines
Quoted 3 lines
Review
Quoted 3 lines
---8<---
(quoted diff) +0
-0
b/drivers/iommu/intel/iommu.cQuoted 4 lines
drivers/iommu/intel/iommu.c static int
Quoted 4 lines
index
956a02eb40b4..0ee5f1bd8af2100644drivers/iommu/intel/iommu.c +0
-0@@ -658,7 +658,14 @@ static intdomain_update_iommu_snooping(struct
Quoted 18 lines
Quoted 18 lines
drivers/iommu/intel/iommu.c +8
-1intel_iommu *skip)rcu_read_lock ();for_each_active_iommu (iommu, drhd) {if (iommu != skip) { -if (!ecap_sc_support (iommu->ecap)) { +/* +* If the hardware is operating in the scalable mode, +* the snooping control is always supported since we +* always set PASID-table-entry.PGSNP bit if the domain +* is managed outside (UNMANAGED). +*/ +if (!sm_supported (iommu) && + !ecap_sc_support (iommu->ecap)) { ret =0 ;break ;}---8<---
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Does it mean that for some hardwares that has
sm_supported()==true,
Quoted 2 lines
Quoted 2 lines
it'll
Quoted 1 line
Quoted 1 line
have SC bit cleared in ecap register? That sounds odd, and not sure
why.
Quoted 10 lines
Quoted 10 lines
Maybe
Quoted 3 lines
Quoted 1 line
Yi Liu or Yi Sun may know?
scalable mode has no dependency on SC, so it's possible.
I see; thanks, Yi.
However then OTOH I don't understand above comment
"If the hardware is operating in the scalable mode, the snooping control
is
Quoted 8 lines
Quoted 4 lines
always supported since... "
Because the current qemu vt-d emulation should fall into the case that Yi mentioned - we support initial scalable mode but no SC yet..
chapter 3.9 of 3.2 spec says below.
“If the remapping hardware is setup in scalable-mode
(RTADDR_REG.TTM=01b)
Quoted 1 line
and the Page Snoop (PGSNP) field in PASID-table entry is Set, access to
the
Quoted 5 lines
final page is snooped.”
It means the PGSNP field is available under scalable mode. And spec also says below in chapter 96. of 3.2 spec.
Quoted 8 lines
"Requests snoop processor caches irrespective of, other attributes in the request or other fields in paging structure entries used to translate the request."
It means the PGSNP field of PASID table entry is the first class control of the snoop behaviour. Also it means the scalable mode has the snoop control by default. ^_^. So the comment in the above commit is correct since the policy of intel iommu driver is always setting the PGSNP bit.
I see. Setting PGSNP bit in the pasid entry looks fine to me.
Quoted 9 lines
However IIUC what's triggering the crash (that Jason is fixing) is the guest iommu driver "thinks" SC is supported since scalable is enabled (even if qemu vIOMMU has declared ECAP.SC==0 there), then it'll update
iommu_snoopingbit, then it'll try to attach the SNP bit in the 2nd level pgtable (intel_iommu_map):if ((iommu_prot & IOMMU_CACHE) && dmar_domain->iommu_snooping) prot |= DMA_PTE_SNP;Above is the fact today.
Quoted 5 lines
So what I'm wondering is: whether the kernel should _not_ set SNP bit in the 2nd level pgtable, even if we set PGSNP in the pasid entry.. because as you mentioned, the hardware (here the emulated vIOMMU) is allowed to have both scalable==1 but sc==0 so it may recognize PGSNP in pasid entry but not the SNP bit in pgtables.
Quoted 4 lines
This is a weird configuration. :( let's fix it in spec. e.g. PGSNP bit is supported only when scalable==1 and sc==1. this makes more sense. right? Then SNP bit will always depend on sc bit, it won't have any relationship with scalable bit.
Sounds reasonable.
Quoted 11 lines
Quoted 7 lines
If we'll skip pgtable SNP bit anyway for scalable mode, it looks weird to explicitly set it too.
I think it's fine for Jason's solution to just skip checking SNP bit so we ignore it in qemu, however just to double check we're on the same page.
If we have above fix in spec, the iommu driver would also update its behavior on the SNP bit. then the problem encountered by Jason will go away. right?
Looks right to me.
I think we can still have Jason's patch continued because the kernel commit to apply SNP bit is merged in v5.13, so we may need the qemu change to let it still work with v5.13-v5.15+ guest kernels. We'll loose the resv bit check a bit, but looks worthwhile. Jason?
Thanks,
Signature · 1 line
Peter Xu
Quoted 143 lines · Peter Xu
Quoted 122 lines · Yi L
Quoted 104 lines
From: Peter Xu <[email protected]>
Sent: Thursday, November 25, 2021 2:14 PMQuoted 11 lines · Yi L
Quoted 11 lines
From: Peter Xu <[email protected]>
Sent: Thursday, November 25, 2021 12:31 PMQuoted 7 lines · Yi L
Quoted 7 lines
From: Peter Xu <[email protected]>
Sent: Wednesday, November 24, 2021 3:57 PMQuoted 3 lines · Jason Wang
When booting with scalable mode, I hit this error:
qemu-system-x86_64:
vtd_iova_to_slpte: detected splte reservenon-
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
zero iova=0xfffff002, level=0x1slpte=0x102681803)
Quoted 1 line
qemu-system-x86_64:
vtd_iommu_translate: detected translationfailure
Quoted 2 lines
Quoted 2 lines
(dev=01:00:00, iova=0xfffff002)
Quoted 1 line
qemu-system-x86_64: New fault is not recorded due to
compression
Quoted 11 lines
Quoted 11 lines
of
Quoted 4 lines
Quoted 4 lines
faults
Quoted 3 lines
This is because the SNP bit is set since Linux kernel commit
6c00612d0cba1("iommu/vt-d: Report right snoop capability whenusing
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
FL for IOVA") where SNP bit is set if scalable mode is on though this seems to be an violation on the spec which said the SNP bit is considered to be reserved if SC is not supported.
When I was reading that commit, I was actually confused by this
change:
Quoted 27 lines
Quoted 27 lines
Quoted 3 lines
Review
Quoted 3 lines
---8<---
(quoted diff) +0
-0
b/drivers/iommu/intel/iommu.cQuoted 4 lines
drivers/iommu/intel/iommu.c static int
Quoted 4 lines
index
956a02eb40b4..0ee5f1bd8af2100644drivers/iommu/intel/iommu.c +0
-0@@ -658,7 +658,14 @@ static intdomain_update_iommu_snooping(struct
Quoted 18 lines
Quoted 18 lines
drivers/iommu/intel/iommu.c +8
-1intel_iommu *skip)rcu_read_lock ();for_each_active_iommu (iommu, drhd) {if (iommu != skip) { -if (!ecap_sc_support (iommu->ecap)) { +/* +* If the hardware is operating in the scalable mode, +* the snooping control is always supported since we +* always set PASID-table-entry.PGSNP bit if the domain +* is managed outside (UNMANAGED). +*/ +if (!sm_supported (iommu) && + !ecap_sc_support (iommu->ecap)) { ret =0 ;break ;}---8<---
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Does it mean that for some hardwares that has
sm_supported()==true,
Quoted 2 lines
Quoted 2 lines
it'll
Quoted 1 line
Quoted 1 line
have SC bit cleared in ecap register? That sounds odd, and not sure
why.
Quoted 10 lines
Quoted 10 lines
Maybe
Quoted 3 lines
Quoted 1 line
Yi Liu or Yi Sun may know?
scalable mode has no dependency on SC, so it's possible.
I see; thanks, Yi.
However then OTOH I don't understand above comment
"If the hardware is operating in the scalable mode, the snooping control
is
Quoted 8 lines
Quoted 4 lines
always supported since... "
Because the current qemu vt-d emulation should fall into the case that Yi mentioned - we support initial scalable mode but no SC yet..
chapter 3.9 of 3.2 spec says below.
“If the remapping hardware is setup in scalable-mode
(RTADDR_REG.TTM=01b)
Quoted 1 line
and the Page Snoop (PGSNP) field in PASID-table entry is Set, access to
the
Quoted 5 lines
final page is snooped.”
It means the PGSNP field is available under scalable mode. And spec also says below in chapter 96. of 3.2 spec.
Quoted 8 lines
"Requests snoop processor caches irrespective of, other attributes in the request or other fields in paging structure entries used to translate the request."
It means the PGSNP field of PASID table entry is the first class control of the snoop behaviour. Also it means the scalable mode has the snoop control by default. ^_^. So the comment in the above commit is correct since the policy of intel iommu driver is always setting the PGSNP bit.
I see. Setting PGSNP bit in the pasid entry looks fine to me.
Quoted 9 lines
However IIUC what's triggering the crash (that Jason is fixing) is the guest iommu driver "thinks" SC is supported since scalable is enabled (even if qemu vIOMMU has declared ECAP.SC==0 there), then it'll update
iommu_snoopingbit, then it'll try to attach the SNP bit in the 2nd level pgtable (intel_iommu_map):if ((iommu_prot & IOMMU_CACHE) && dmar_domain->iommu_snooping) prot |= DMA_PTE_SNP;Above is the fact today.
Quoted 5 lines
So what I'm wondering is: whether the kernel should _not_ set SNP bit in the 2nd level pgtable, even if we set PGSNP in the pasid entry.. because as you mentioned, the hardware (here the emulated vIOMMU) is allowed to have both scalable==1 but sc==0 so it may recognize PGSNP in pasid entry but not the SNP bit in pgtables.
Quoted 4 lines
This is a weird configuration. :( let's fix it in spec. e.g. PGSNP bit is supported only when scalable==1 and sc==1. this makes more sense. right? Then SNP bit will always depend on sc bit, it won't have any relationship with scalable bit.
Sounds reasonable.
Quoted 11 lines
Quoted 7 lines
If we'll skip pgtable SNP bit anyway for scalable mode, it looks weird to explicitly set it too.
I think it's fine for Jason's solution to just skip checking SNP bit so we ignore it in qemu, however just to double check we're on the same page.
If we have above fix in spec, the iommu driver would also update its behavior on the SNP bit. then the problem encountered by Jason will go away. right?
Quoted 6 lines
Looks right to me.
I think we can still have Jason's patch continued because the kernel commit to apply SNP bit is merged in v5.13, so we may need the qemu change to let it still work with v5.13-v5.15+ guest kernels. We'll loose the resv bit check a bit, but looks worthwhile. Jason?
Yes, I agree. The only thing that may worry me is the migration compatibility. If we migrate from new to old we may break the guests, we probably need compatibility props for that.
And in the future, it could be even more troublesome,e.g there's one day we found another bit that needs not to be checked. Maybe we should even remove all the rsvd bits checks?
Thanks
Quoted 6 lines
Thanks,
--
Peter Xu
Quoted 8 lines · Jason Wang
Quoted 4 lines
I think we can still have Jason's patch continued because the kernel commit to apply SNP bit is merged in v5.13, so we may need the qemu change to let it still work with v5.13-v5.15+ guest kernels. We'll loose the resv bit check a bit, but looks worthwhile. Jason?
Yes, I agree. The only thing that may worry me is the migration compatibility. If we migrate from new to old we may break the guests, we probably need compatibility props for that.
Hmm.. How important is new->old migrations? Is that normally for the old->new->old migration so that users can always fallback to the old hosts?
If that's the case then IMHO we're fine here, since the new binary check less on resv bits than the old binary, then if the guest code can work with the old binary already then migrating back to old binary should work too. Changing guest OS during migration of new->old can have a problem but hopefully rare.
OTOH - do you know any of the real enterprise user that uses scalable mode yet? To my own understanding it's still mostly "experimental", then hopefully we can avoid worrying on that too much?
Quoted 4 lines
And in the future, it could be even more troublesome,e.g there's one day we found another bit that needs not to be checked. Maybe we should even remove all the rsvd bits checks?
When a real hardware sees any of the reserved bits set, it'll bail out and raise an error, right?
If that's the case, I'm wondering whether we should always follow the hardware behavior as an emulator.
Now I'm trying to remember normally how a spec could re-use a bit that was used to be reserved: should the hardware bumps the version of the version reg in so that softwares will know what to expect?
So I'm thinking whether the emulator code can identify the version bump by "scalable mode enabled", if so we know some resved bits are "ignored" now, and IIUC that's mostly the original proposal to add a quirk when scalable mode in vtd_init().
But again, I really think it should be the spec owner who should have considered all these.. e.g. explicitly document "this bit was used to reserved, but when scalable mode enabled it's ignored and programmable by the guest driver", or something like that.
Thanks,
Signature · 1 line
Peter Xu
Quoted 7 lines · Peter Xu
Quoted 5 lines · Jason Wang
Quoted 4 lines
I think we can still have Jason's patch continued because the kernel commit to apply SNP bit is merged in v5.13, so we may need the qemu change to let it still work with v5.13-v5.15+ guest kernels. We'll loose the resv bit check a bit, but looks worthwhile. Jason?
Quoted 6 lines
Quoted 3 lines
Yes, I agree. The only thing that may worry me is the migration compatibility. If we migrate from new to old we may break the guests, we probably need compatibility props for that.
Hmm.. How important is
new->oldmigrations? Is that normally for theold->new->oldmigration so that users can always fallback to the old hosts?
I meant e.g migrating from new qemu with machine=6.3 to old qemu with machine=6.3.
So guest works on the src but not dst.
Quoted 9 lines
If that's the case then IMHO we're fine here, since the new binary check less on resv bits than the old binary, then if the guest code can work with the old binary already then migrating back to old binary should work too. Changing guest OS during migration of
new->oldcan have a problem but hopefully rare.OTOH - do you know any of the real enterprise user that uses scalable mode yet? To my own understanding it's still mostly "experimental", then hopefully we can avoid worrying on that too much?
Probably, it has an "x" prefix.
Quoted 8 lines
Quoted 5 lines
And in the future, it could be even more troublesome,e.g there's one day we found another bit that needs not to be checked. Maybe we should even remove all the rsvd bits checks?
When a real hardware sees any of the reserved bits set, it'll bail out and raise an error, right?
To say the truth I don't know (though spec said that).
Quoted 7 lines
If that's the case, I'm wondering whether we should always follow the hardware behavior as an emulator.
Now I'm trying to remember normally how a spec could re-use a bit that was used to be reserved: should the hardware bumps the version of the version reg in so that softwares will know what to expect?
I think so or at least some kind of negotiation.
Quoted 10 lines
So I'm thinking whether the emulator code can identify the version bump by "scalable mode enabled", if so we know some resved bits are "ignored" now, and IIUC that's mostly the original proposal to add a quirk when scalable mode in
vtd_init().But again, I really think it should be the spec owner who should have considered all these.. e.g. explicitly document "this bit was used to reserved, but when scalable mode enabled it's ignored and programmable by the guest driver", or something like that.
I fully agree, we've learnt a lot when dealing with migration compatibility in the past decade.
I will prepare a V2, it was basically what you suggested. And we can leave the rest for future investigation. The motivation is prototyping PASID support for virtio, it's sufficient for this patch to unblock the work.
Thanks
Quoted 6 lines
Thanks,
--
Peter Xu
Quoted 11 lines
From: Peter Xu <[email protected]>
Sent: Monday, November 29, 2021 11:14 AMQuoted 4 lines · Jason Wang
And in the future, it could be even more troublesome,e.g there's one day we found another bit that needs not to be checked. Maybe we should even remove all the rsvd bits checks?
When a real hardware sees any of the reserved bits set, it'll bail out and raise an error, right?
I think so. vtd spec has defined Non-zero reserved field error code against all the translation structures (root/context/pasid dir/pasid table/page table) for it. And it makes sense since any such error indicates a potential misunderstanding on the spec.
Quoted 2 lines
If that's the case, I'm wondering whether we should always follow the hardware behavior as an emulator.
I think so. and current virtual Intel IOMMU does a good job to detect the SNP setting.:)
Quoted 3 lines
Now I'm trying to remember normally how a spec could re-use a bit that was used to be reserved: should the hardware bumps the version of the version reg in so that softwares will know what to expect?
defining a new capability bit is also a way for it. New software will probe the capability bit and then program the bit which was reserved but now redefined. Old software doesn’t have any idea on the new capability bit, so it will not program the reserved bit.
Quoted 4 lines
So I'm thinking whether the emulator code can identify the version bump by "scalable mode enabled", if so we know some resved bits are "ignored" now, and IIUC that's mostly the original proposal to add a quirk when scalable mode in
vtd_init().
do you mean the spec version or?
Quoted 2 lines
But again, I really think it should be the spec owner who should have considered all these..
yes, spec owner should consider it.
Quoted 3 lines
e.g. explicitly document "this bit was used to reserved,
but when scalable mode enabled it's ignored and programmable by the guest driver", or something like that.
there is a good example for your above sentence. It's the root table entry and the scalable mode root table entry. In legacy mode, the high 64 bits of root table entry are all reserved. In scalable mode, some of the high 64 bits are used. I think we have defined scalable mode reserved bits macro in the emulator code.
But regards to minor changes within a working mode, it may be more common to define a capability bit when a reserved bit is re-used.
Regards,
Yi Liu