From: Jason Wang <jasowang@redhat.com>
To: mst@redhat.com, peterx@redhat.com
Cc: Jason Wang <jasowang@redhat.com>,
yi.l.liu@intel.com, yi.y.sun@linux.intel.com,
qemu-devel@nongnu.org
Subject: [PATCH] intel-iommu: correctly check passthrough during translation
Date: Wed, 5 Jan 2022 12:19:42 +0800 [thread overview]
Message-ID: <20220105041945.13459-2-jasowang@redhat.com> (raw)
In-Reply-To: <20220105041945.13459-1-jasowang@redhat.com>
When scsalable 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>
---
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 f584449d8d..f346a82652 100644
--- a/hw/i386/intel_iommu.c
+++ b/hw/i386/intel_iommu.c
@@ -1512,11 +1512,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);
@@ -1534,17 +1552,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. */
@@ -1556,7 +1564,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),
@@ -1749,7 +1757,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;
--
2.25.1
next prev parent reply other threads:[~2022-01-05 4:22 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-05 4:19 [PATCH 0/3] PASID support for Intel IOMMU Jason Wang
2022-01-05 4:19 ` Jason Wang [this message]
2022-01-05 4:19 ` [PATCH 1/3] intel-iommu: don't warn guest errors when getting rid2pasid entry Jason Wang
2022-01-13 3:35 ` Peter Xu
2022-01-13 6:16 ` Jason Wang
2022-01-13 6:32 ` Peter Xu
2022-01-13 7:05 ` Michael S. Tsirkin
2022-01-14 3:02 ` Jason Wang
2022-01-13 7:06 ` Michael S. Tsirkin
2022-01-14 2:56 ` Jason Wang
2022-01-05 4:19 ` [PATCH 2/3] intel-iommu: drop VTDBus Jason Wang
2022-01-13 4:12 ` Peter Xu
2022-01-14 2:32 ` Jason Wang
2022-01-14 9:15 ` Jason Wang
2022-01-17 1:27 ` Peter Xu
2022-01-17 1:42 ` Peter Xu
2022-01-05 4:19 ` [PATCH 3/3] intel-iommu: PASID support Jason Wang
2022-01-13 5:06 ` Peter Xu
2022-01-13 7:16 ` Michael S. Tsirkin
2022-01-14 2:47 ` Jason Wang
2022-01-14 3:31 ` Peter Xu
2022-01-14 5:58 ` Jason Wang
2022-01-14 7:13 ` Peter Xu
2022-01-14 7:22 ` Jason Wang
2022-01-14 7:45 ` Peter Xu
2022-01-14 9:12 ` Jason Wang
2022-01-14 12:58 ` Liu Yi L
2022-01-17 6:01 ` Jason Wang
-- strict thread matches above, loose matches on Subject: below --
2021-12-22 6:39 [PATCH] intel-iommu: correctly check passthrough during translation Jason Wang
2021-12-22 11:38 ` Peter Xu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220105041945.13459-2-jasowang@redhat.com \
--to=jasowang@redhat.com \
--cc=mst@redhat.com \
--cc=peterx@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=yi.l.liu@intel.com \
--cc=yi.y.sun@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).