qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Joao Martins <joao.m.martins@oracle.com>
To: qemu-devel@nongnu.org
Cc: "John G . Johnson" <john.g.johnson@oracle.com>,
	kvm@vger.kernel.org, "Michael S. Tsirkin" <mst@redhat.com>,
	"Jason Wang" <jasowang@redhat.com>,
	"Peter Xu" <peterx@redhat.com>,
	"Joao Martins" <joao.m.martins@oracle.com>,
	"Eric Blake" <eblake@redhat.com>, "Yi Liu" <yi.l.liu@intel.com>,
	"Juan Quintela" <quintela@redhat.com>,
	"David Hildenbrand" <david@redhat.com>,
	"Markus Armbruster" <armbru@redhat.com>,
	"Nicolin Chen" <nicolinc@nvidia.com>,
	"Jason Gunthorpe" <jgg@nvidia.com>,
	"Kevin Tian" <kevin.tian@intel.com>,
	"Richard Henderson" <richard.henderson@linaro.org>,
	"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
	"Eric Auger" <eric.auger@redhat.com>,
	"Alex Williamson" <alex.williamson@redhat.com>,
	"Thanos Makatos" <thanos.makatos@nutanix.com>,
	"Eduardo Habkost" <eduardo@habkost.net>,
	"Yishai Hadas" <yishaih@nvidia.com>,
	"Cornelia Huck" <cohuck@redhat.com>,
	"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
	"Paolo Bonzini" <pbonzini@redhat.com>
Subject: [PATCH RFC 03/10] intel-iommu: Cache PASID entry flags
Date: Thu, 28 Apr 2022 22:13:44 +0100	[thread overview]
Message-ID: <20220428211351.3897-4-joao.m.martins@oracle.com> (raw)
In-Reply-To: <20220428211351.3897-1-joao.m.martins@oracle.com>

On a successful translation, cache the PASID Table entry
flags set at the context at the time i.e. the first 12bits.
These bits contain read, write, dirty and access for example.

This is a preparatory for SSADS which requires updating A/D
bits on a translation based on the fact that SSADS was enabled
on the given scalable mode PASID Table entry.

Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
---
 hw/i386/intel_iommu.c         | 18 ++++++++++++++++--
 include/hw/i386/intel_iommu.h |  1 +
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c
index c64aa81a83fc..752940fa4c0e 100644
--- a/hw/i386/intel_iommu.c
+++ b/hw/i386/intel_iommu.c
@@ -314,7 +314,7 @@ out:
 /* Must be with IOMMU lock held */
 static void vtd_update_iotlb(IntelIOMMUState *s, uint16_t source_id,
                              uint16_t domain_id, hwaddr addr, uint64_t slpte,
-                             uint8_t access_flags, uint32_t level)
+                             uint8_t access_flags, uint32_t level, uint16_t pe)
 {
     VTDIOTLBEntry *entry = g_malloc(sizeof(*entry));
     uint64_t *key = g_malloc(sizeof(*key));
@@ -331,6 +331,7 @@ static void vtd_update_iotlb(IntelIOMMUState *s, uint16_t source_id,
     entry->slpte = slpte;
     entry->access_flags = access_flags;
     entry->mask = vtd_slpt_level_page_mask(level);
+    entry->sm_pe_flags = pe;
     *key = vtd_get_iotlb_key(gfn, source_id, level);
     g_hash_table_replace(s->iotlb, key, entry);
 }
@@ -965,6 +966,19 @@ static dma_addr_t vtd_get_iova_pgtbl_base(IntelIOMMUState *s,
     return vtd_ce_get_slpt_base(ce);
 }
 
+static uint64_t vtd_sm_pasid_entry_flags(IntelIOMMUState *s,
+                                         VTDContextEntry *ce)
+{
+    VTDPASIDEntry pe;
+
+    if (!s->root_scalable) {
+        return 0;
+    }
+
+    vtd_ce_get_rid2pasid_entry(s, ce, &pe);
+    return pe.val[0] & (~VTD_SM_PASID_ENTRY_SLPTPTR);
+}
+
 /*
  * Rsvd field masks for spte:
  *     vtd_spte_rsvd 4k pages
@@ -1789,7 +1803,7 @@ static bool vtd_do_iommu_translate(VTDAddressSpace *vtd_as, PCIBus *bus,
     page_mask = vtd_slpt_level_page_mask(level);
     access_flags = IOMMU_ACCESS_FLAG(reads, writes);
     vtd_update_iotlb(s, source_id, vtd_get_domain_id(s, &ce), addr, slpte,
-                     access_flags, level);
+                     access_flags, level, vtd_sm_pasid_entry_flags(s, &ce));
 out:
     vtd_iommu_unlock(s);
     entry->iova = addr & page_mask;
diff --git a/include/hw/i386/intel_iommu.h b/include/hw/i386/intel_iommu.h
index 3b5ac869db6e..11446012a94c 100644
--- a/include/hw/i386/intel_iommu.h
+++ b/include/hw/i386/intel_iommu.h
@@ -123,6 +123,7 @@ struct VTDIOTLBEntry {
     uint64_t slpte;
     uint64_t mask;
     uint8_t access_flags;
+    uint16_t sm_pe_flags;
 };
 
 /* VT-d Source-ID Qualifier types */
-- 
2.17.2



  parent reply	other threads:[~2022-04-28 21:25 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-28 21:13 [PATCH RFC 00/10] hw/vfio, x86/iommu: IOMMUFD Dirty Tracking Joao Martins
2022-04-28 21:13 ` [PATCH RFC 01/10] amd-iommu: Cache PTE/DTE info in IOTLB Joao Martins
2022-04-28 21:13 ` [PATCH RFC 02/10] amd-iommu: Access/Dirty bit support Joao Martins
2022-04-28 21:13 ` Joao Martins [this message]
2022-04-28 21:13 ` [PATCH RFC 04/10] intel_iommu: Second Stage Access Dirty " Joao Martins
2022-04-29  2:26   ` Jason Wang
2022-04-29  9:12     ` Joao Martins
2022-04-29 18:21       ` Peter Xu
2022-05-03 11:54         ` Joao Martins
2022-05-05  7:41           ` Jason Wang
2022-05-05  9:57             ` Joao Martins
2022-05-04 20:11   ` Peter Xu
2022-05-05  9:54     ` Joao Martins
2022-04-28 21:13 ` [PATCH RFC 05/10] linux-headers: import iommufd.h hwpt extensions Joao Martins
2022-04-28 21:13 ` [PATCH RFC 06/10] vfio/iommufd: Add HWPT_SET_DIRTY support Joao Martins
2022-04-28 21:13 ` [PATCH RFC 07/10] vfio/iommufd: Add HWPT_GET_DIRTY_IOVA support Joao Martins
2022-04-28 21:13 ` [PATCH RFC 08/10] vfio/iommufd: Add IOAS_UNMAP_DIRTY support Joao Martins
2022-04-28 21:13 ` [PATCH RFC 09/10] migration/dirtyrate: Expand dirty_bitmap to be tracked separately for devices Joao Martins
2022-05-02 12:54   ` Markus Armbruster
2022-05-02 14:35     ` Joao Martins
2022-04-28 21:13 ` [PATCH RFC 10/10] hw/vfio: Add nr of dirty pages to tracepoints Joao Martins

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=20220428211351.3897-4-joao.m.martins@oracle.com \
    --to=joao.m.martins@oracle.com \
    --cc=alex.williamson@redhat.com \
    --cc=armbru@redhat.com \
    --cc=cohuck@redhat.com \
    --cc=david@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=eblake@redhat.com \
    --cc=eduardo@habkost.net \
    --cc=eric.auger@redhat.com \
    --cc=f4bug@amsat.org \
    --cc=jasowang@redhat.com \
    --cc=jgg@nvidia.com \
    --cc=john.g.johnson@oracle.com \
    --cc=kevin.tian@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=nicolinc@nvidia.com \
    --cc=pbonzini@redhat.com \
    --cc=peterx@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.com \
    --cc=richard.henderson@linaro.org \
    --cc=thanos.makatos@nutanix.com \
    --cc=yi.l.liu@intel.com \
    --cc=yishaih@nvidia.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).