intel_iommu: use access_flags for iotlb

It was cached by read/write separately. Let's merge them.

Signed-off-by: Peter Xu <peterx@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
This commit is contained in:
Peter Xu 2017-07-17 17:02:30 +08:00 committed by Michael S. Tsirkin
parent 892721d91d
commit 07f7b73398
2 changed files with 8 additions and 10 deletions

View File

@ -237,8 +237,7 @@ out:
static void vtd_update_iotlb(IntelIOMMUState *s, uint16_t source_id, static void vtd_update_iotlb(IntelIOMMUState *s, uint16_t source_id,
uint16_t domain_id, hwaddr addr, uint64_t slpte, uint16_t domain_id, hwaddr addr, uint64_t slpte,
bool read_flags, bool write_flags, uint8_t access_flags, uint32_t level)
uint32_t level)
{ {
VTDIOTLBEntry *entry = g_malloc(sizeof(*entry)); VTDIOTLBEntry *entry = g_malloc(sizeof(*entry));
uint64_t *key = g_malloc(sizeof(*key)); uint64_t *key = g_malloc(sizeof(*key));
@ -253,8 +252,7 @@ static void vtd_update_iotlb(IntelIOMMUState *s, uint16_t source_id,
entry->gfn = gfn; entry->gfn = gfn;
entry->domain_id = domain_id; entry->domain_id = domain_id;
entry->slpte = slpte; entry->slpte = slpte;
entry->read_flags = read_flags; entry->access_flags = access_flags;
entry->write_flags = write_flags;
entry->mask = vtd_slpt_level_page_mask(level); entry->mask = vtd_slpt_level_page_mask(level);
*key = vtd_get_iotlb_key(gfn, source_id, level); *key = vtd_get_iotlb_key(gfn, source_id, level);
g_hash_table_replace(s->iotlb, key, entry); g_hash_table_replace(s->iotlb, key, entry);
@ -1087,6 +1085,7 @@ static bool vtd_do_iommu_translate(VTDAddressSpace *vtd_as, PCIBus *bus,
bool is_fpd_set = false; bool is_fpd_set = false;
bool reads = true; bool reads = true;
bool writes = true; bool writes = true;
uint8_t access_flags;
VTDIOTLBEntry *iotlb_entry; VTDIOTLBEntry *iotlb_entry;
/* /*
@ -1101,8 +1100,7 @@ static bool vtd_do_iommu_translate(VTDAddressSpace *vtd_as, PCIBus *bus,
trace_vtd_iotlb_page_hit(source_id, addr, iotlb_entry->slpte, trace_vtd_iotlb_page_hit(source_id, addr, iotlb_entry->slpte,
iotlb_entry->domain_id); iotlb_entry->domain_id);
slpte = iotlb_entry->slpte; slpte = iotlb_entry->slpte;
reads = iotlb_entry->read_flags; access_flags = iotlb_entry->access_flags;
writes = iotlb_entry->write_flags;
page_mask = iotlb_entry->mask; page_mask = iotlb_entry->mask;
goto out; goto out;
} }
@ -1172,13 +1170,14 @@ static bool vtd_do_iommu_translate(VTDAddressSpace *vtd_as, PCIBus *bus,
} }
page_mask = vtd_slpt_level_page_mask(level); page_mask = vtd_slpt_level_page_mask(level);
access_flags = IOMMU_ACCESS_FLAG(reads, writes);
vtd_update_iotlb(s, source_id, VTD_CONTEXT_ENTRY_DID(ce.hi), addr, slpte, vtd_update_iotlb(s, source_id, VTD_CONTEXT_ENTRY_DID(ce.hi), addr, slpte,
reads, writes, level); access_flags, level);
out: out:
entry->iova = addr & page_mask; entry->iova = addr & page_mask;
entry->translated_addr = vtd_get_slpte_addr(slpte) & page_mask; entry->translated_addr = vtd_get_slpte_addr(slpte) & page_mask;
entry->addr_mask = ~page_mask; entry->addr_mask = ~page_mask;
entry->perm = IOMMU_ACCESS_FLAG(reads, writes); entry->perm = access_flags;
return true; return true;
error: error:

View File

@ -103,8 +103,7 @@ struct VTDIOTLBEntry {
uint16_t domain_id; uint16_t domain_id;
uint64_t slpte; uint64_t slpte;
uint64_t mask; uint64_t mask;
bool read_flags; uint8_t access_flags;
bool write_flags;
}; };
/* VT-d Source-ID Qualifier types */ /* VT-d Source-ID Qualifier types */