@@ -158,6 +158,7 @@ struct MemoryRegion {
bool rom_device;
bool warning_printed; /* For reservations */
bool flush_coalesced_mmio;
+ bool uncached;
MemoryRegion *alias;
hwaddr alias_offset;
int32_t priority;
@@ -778,6 +779,30 @@ void memory_region_set_flush_coalesced(MemoryRegion *mr);
void memory_region_clear_flush_coalesced(MemoryRegion *mr);
/**
+ * memory_region_set_uncached: Flag this memory region (for e.g. kvm) as
+ * typically being mapped uncached.
+ *
+ * @mr: the memory region to be updated.
+ */
+void memory_region_set_uncached(MemoryRegion *mr);
+
+/**
+ * memory_region_clear_uncached: Remove the 'uncached' flag.
+ *
+ * @mr: the memory region to be updated.
+ */
+void memory_region_clear_uncached(MemoryRegion *mr);
+
+/**
+ * memory_region_may_map_uncached: Return the 'uncached' flag, which
+ * indicates the region is typically
+ * mapped uncached.
+ *
+ * @mr: the memory region to check.
+ */
+bool memory_region_may_map_uncached(MemoryRegion *mr);
+
+/**
* memory_region_add_eventfd: Request an eventfd to be triggered when a word
* is written to a location.
*
@@ -126,6 +126,7 @@ bool kvm_gsi_routing_allowed;
bool kvm_gsi_direct_mapping;
bool kvm_allowed;
bool kvm_readonly_mem_allowed;
+bool kvm_uncached_mem_allowed;
bool kvm_vm_attributes_allowed;
static const KVMCapabilityInfo kvm_required_capabilites[] = {
@@ -306,6 +307,9 @@ static int kvm_mem_flags(MemoryRegion *mr)
if (readonly && kvm_readonly_mem_allowed) {
flags |= KVM_MEM_READONLY;
}
+ if (memory_region_may_map_uncached(mr) && kvm_uncached_mem_allowed) {
+ flags |= KVM_MEM_UNCACHED;
+ }
return flags;
}
@@ -1595,6 +1599,11 @@ static int kvm_init(MachineState *ms)
(kvm_check_extension(s, KVM_CAP_READONLY_MEM) > 0);
#endif
+#ifdef KVM_CAP_UNCACHED_MEM
+ kvm_uncached_mem_allowed =
+ (kvm_check_extension(s, KVM_CAP_UNCACHED_MEM) > 0);
+#endif
+
kvm_eventfds_allowed =
(kvm_check_extension(s, KVM_CAP_IOEVENTFD) > 0);
@@ -1549,6 +1549,21 @@ void memory_region_clear_flush_coalesced(MemoryRegion *mr)
}
}
+void memory_region_set_uncached(MemoryRegion *mr)
+{
+ mr->uncached = true;
+}
+
+void memory_region_clear_uncached(MemoryRegion *mr)
+{
+ mr->uncached = false;
+}
+
+bool memory_region_may_map_uncached(MemoryRegion *mr)
+{
+ return mr->uncached;
+}
+
void memory_region_add_eventfd(MemoryRegion *mr,
hwaddr addr,
unsigned size,
Add an 'uncached' flag, which will result in the KVM_MEM_UNCACHED flag getting set on KVM's corresponding memory slot. Signed-off-by: Andrew Jones <drjones@redhat.com> --- include/exec/memory.h | 25 +++++++++++++++++++++++++ kvm-all.c | 9 +++++++++ memory.c | 15 +++++++++++++++ 3 files changed, 49 insertions(+)