[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL v2 42/55] intel-iommu: correctly check passthrough during translat
|
From: |
Michael S. Tsirkin |
|
Subject: |
[PULL v2 42/55] intel-iommu: correctly check passthrough during translation |
|
Date: |
Fri, 7 Jan 2022 06:05:10 -0500 |
From: Jason Wang <jasowang@redhat.com>
When scalable mode is enabled, the passthrough more is not determined
by the context entry but PASID entry, so switch to use the logic of
vtd_dev_pt_enabled() to determine the passthrough mode in
vtd_do_iommu_translate().
Signed-off-by: Jason Wang <jasowang@redhat.com>
Message-Id: <20220105041945.13459-2-jasowang@redhat.com>
Reviewed-by: Peter Xu <peterx@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
hw/i386/intel_iommu.c | 38 +++++++++++++++++++++++---------------
1 file changed, 23 insertions(+), 15 deletions(-)
diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c
index 5b865ac08c..4c6c016388 100644
--- a/hw/i386/intel_iommu.c
+++ b/hw/i386/intel_iommu.c
@@ -1516,11 +1516,29 @@ static int vtd_sync_shadow_page_table(VTDAddressSpace
*vtd_as)
* 1st-level translation or 2nd-level translation, it depends
* on PGTT setting.
*/
-static bool vtd_dev_pt_enabled(VTDAddressSpace *as)
+static bool vtd_dev_pt_enabled(IntelIOMMUState *s, VTDContextEntry *ce)
+{
+ VTDPASIDEntry pe;
+ int ret;
+
+ if (s->root_scalable) {
+ ret = vtd_ce_get_rid2pasid_entry(s, ce, &pe);
+ if (ret) {
+ error_report_once("%s: vtd_ce_get_rid2pasid_entry error: %"PRId32,
+ __func__, ret);
+ return false;
+ }
+ return (VTD_PE_GET_TYPE(&pe) == VTD_SM_PASID_ENTRY_PT);
+ }
+
+ return (vtd_ce_get_type(ce) == VTD_CONTEXT_TT_PASS_THROUGH);
+
+}
+
+static bool vtd_as_pt_enabled(VTDAddressSpace *as)
{
IntelIOMMUState *s;
VTDContextEntry ce;
- VTDPASIDEntry pe;
int ret;
assert(as);
@@ -1538,17 +1556,7 @@ static bool vtd_dev_pt_enabled(VTDAddressSpace *as)
return false;
}
- if (s->root_scalable) {
- ret = vtd_ce_get_rid2pasid_entry(s, &ce, &pe);
- if (ret) {
- error_report_once("%s: vtd_ce_get_rid2pasid_entry error: %"PRId32,
- __func__, ret);
- return false;
- }
- return (VTD_PE_GET_TYPE(&pe) == VTD_SM_PASID_ENTRY_PT);
- }
-
- return (vtd_ce_get_type(&ce) == VTD_CONTEXT_TT_PASS_THROUGH);
+ return vtd_dev_pt_enabled(s, &ce);
}
/* Return whether the device is using IOMMU translation. */
@@ -1560,7 +1568,7 @@ static bool vtd_switch_address_space(VTDAddressSpace *as)
assert(as);
- use_iommu = as->iommu_state->dmar_enabled && !vtd_dev_pt_enabled(as);
+ use_iommu = as->iommu_state->dmar_enabled && !vtd_as_pt_enabled(as);
trace_vtd_switch_address_space(pci_bus_num(as->bus),
VTD_PCI_SLOT(as->devfn),
@@ -1753,7 +1761,7 @@ static bool vtd_do_iommu_translate(VTDAddressSpace
*vtd_as, PCIBus *bus,
* We don't need to translate for pass-through context entries.
* Also, let's ignore IOTLB caching as well for PT devices.
*/
- if (vtd_ce_get_type(&ce) == VTD_CONTEXT_TT_PASS_THROUGH) {
+ if (vtd_dev_pt_enabled(s, &ce)) {
entry->iova = addr & VTD_PAGE_MASK_4K;
entry->translated_addr = entry->iova;
entry->addr_mask = ~VTD_PAGE_MASK_4K;
--
MST
- [PULL v2 31/55] util/oslib-posix: Introduce and use MemsetContext for touch_all_pages(), (continued)
- [PULL v2 31/55] util/oslib-posix: Introduce and use MemsetContext for touch_all_pages(), Michael S. Tsirkin, 2022/01/07
- [PULL v2 30/55] util/oslib-posix: Support MADV_POPULATE_WRITE for os_mem_prealloc(), Michael S. Tsirkin, 2022/01/07
- [PULL v2 32/55] util/oslib-posix: Don't create too many threads with small memory or little pages, Michael S. Tsirkin, 2022/01/07
- [PULL v2 33/55] util/oslib-posix: Avoid creating a single thread with MADV_POPULATE_WRITE, Michael S. Tsirkin, 2022/01/07
- [PULL v2 36/55] virtio-mem: Support "prealloc=on" option, Michael S. Tsirkin, 2022/01/07
- [PULL v2 43/55] acpi: fix QEMU crash when started with SLIC table, Michael S. Tsirkin, 2022/01/07
- [PULL v2 34/55] util/oslib-posix: Support concurrent os_mem_prealloc() invocation, Michael S. Tsirkin, 2022/01/07
- [PULL v2 41/55] virtio-mem: Set "unplugged-inaccessible=auto" for the 7.0 machine on x86, Michael S. Tsirkin, 2022/01/07
- [PULL v2 35/55] util/oslib-posix: Forward SIGBUS to MCE handler under Linux, Michael S. Tsirkin, 2022/01/07
- [PULL v2 40/55] virtio-mem: Support VIRTIO_MEM_F_UNPLUGGED_INACCESSIBLE, Michael S. Tsirkin, 2022/01/07
- [PULL v2 42/55] intel-iommu: correctly check passthrough during translation,
Michael S. Tsirkin <=
- [PULL v2 47/55] acpihp: simplify acpi_pcihp_disable_root_bus, Michael S. Tsirkin, 2022/01/07
- [PULL v2 37/55] virtio: signal after wrapping packed used_idx, Michael S. Tsirkin, 2022/01/07
- [PULL v2 50/55] hw/scsi/vhost-scsi: don't leak vqs on error, Michael S. Tsirkin, 2022/01/07
- [PULL v2 39/55] linux-headers: sync VIRTIO_MEM_F_UNPLUGGED_INACCESSIBLE, Michael S. Tsirkin, 2022/01/07
- [PULL v2 44/55] tests: acpi: whitelist expected blobs before changing them, Michael S. Tsirkin, 2022/01/07
- [PULL v2 45/55] tests: acpi: add SLIC table test, Michael S. Tsirkin, 2022/01/07
- [PULL v2 53/55] tests: acpi: prepare for updated TPM related tables, Michael S. Tsirkin, 2022/01/07
- [PULL v2 46/55] tests: acpi: SLIC: update expected blobs, Michael S. Tsirkin, 2022/01/07
- [PULL v2 38/55] MAINTAINERS: Add a separate entry for acpi/VIOT tables, Michael S. Tsirkin, 2022/01/07
- [PULL v2 51/55] hw/scsi/vhost-scsi: don't double close vhostfd on error, Michael S. Tsirkin, 2022/01/07