Blame SOURCES/kvm-target-i386-sev-Do-not-pin-the-ram-device-memory-reg.patch

Pablo Greco e6a3ae
From 660e7dc57899e79e85c19baa93be009b0382ae8e Mon Sep 17 00:00:00 2001
Pablo Greco e6a3ae
From: Gary R Hook <ghook@redhat.com>
Pablo Greco e6a3ae
Date: Wed, 10 Apr 2019 00:08:03 +0100
Pablo Greco e6a3ae
Subject: [PATCH 3/5] target/i386: sev: Do not pin the ram device memory region
Pablo Greco e6a3ae
Pablo Greco e6a3ae
RH-Author: Gary R Hook <ghook@redhat.com>
Pablo Greco e6a3ae
Message-id: <20190410000803.1744-3-ghook@redhat.com>
Pablo Greco e6a3ae
Patchwork-id: 85542
Pablo Greco e6a3ae
O-Subject: [RHEL-8.1 virt 2/2] target/i386: sev: Do not pin the ram device memory region
Pablo Greco e6a3ae
Bugzilla: 1667249
Pablo Greco e6a3ae
RH-Acked-by: Eduardo Habkost <ehabkost@redhat.com>
Pablo Greco e6a3ae
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
Pablo Greco e6a3ae
RH-Acked-by: Alex Williamson <alex.williamson@redhat.com>
Pablo Greco e6a3ae
Pablo Greco e6a3ae
BZ: 1667249
Pablo Greco e6a3ae
Branch: rhel-8.1.0
Pablo Greco e6a3ae
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1667249
Pablo Greco e6a3ae
Upstream Status: 4.0.0-rc1
Pablo Greco e6a3ae
Build Info: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=20980582
Pablo Greco e6a3ae
Conflicts: None
Pablo Greco e6a3ae
Pablo Greco e6a3ae
commit cedc0ad539afbbb669dba9e73dfad2915bc1c25b
Pablo Greco e6a3ae
Author: Singh, Brijesh <brijesh.singh@amd.com>
Pablo Greco e6a3ae
Date:   Mon Feb 4 22:23:40 2019 +0000
Pablo Greco e6a3ae
Pablo Greco e6a3ae
    target/i386: sev: Do not pin the ram device memory region
Pablo Greco e6a3ae
Pablo Greco e6a3ae
    The RAM device presents a memory region that should be handled
Pablo Greco e6a3ae
    as an IO region and should not be pinned.
Pablo Greco e6a3ae
Pablo Greco e6a3ae
    In the case of the vfio-pci, RAM device represents a MMIO BAR
Pablo Greco e6a3ae
    and the memory region is not backed by pages hence
Pablo Greco e6a3ae
    KVM_MEMORY_ENCRYPT_REG_REGION fails to lock the memory range.
Pablo Greco e6a3ae
Pablo Greco e6a3ae
    Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1667249
Pablo Greco e6a3ae
    Cc: Alex Williamson <alex.williamson@redhat.com>
Pablo Greco e6a3ae
    Cc: Paolo Bonzini <pbonzini@redhat.com>
Pablo Greco e6a3ae
    Signed-off-by: Brijesh Singh <brijesh.singh@amd.com>
Pablo Greco e6a3ae
    Message-Id: <20190204222322.26766-3-brijesh.singh@amd.com>
Pablo Greco e6a3ae
    Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Pablo Greco e6a3ae
Pablo Greco e6a3ae
Cc: Paolo Bonzini <pbonzini@redhat.com>
Pablo Greco e6a3ae
Cc: Richard Henderson <rth@twiddle.net>
Pablo Greco e6a3ae
Cc: Eduardo Habkost <ehabkost@redhat.com>
Pablo Greco e6a3ae
Cc: qemu-devel@nongnu.org
Pablo Greco e6a3ae
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
Pablo Greco e6a3ae
---
Pablo Greco e6a3ae
 target/i386/sev.c | 11 +++++++++++
Pablo Greco e6a3ae
 1 file changed, 11 insertions(+)
Pablo Greco e6a3ae
Pablo Greco e6a3ae
diff --git a/target/i386/sev.c b/target/i386/sev.c
Pablo Greco e6a3ae
index 2395171..b8009b0 100644
Pablo Greco e6a3ae
--- a/target/i386/sev.c
Pablo Greco e6a3ae
+++ b/target/i386/sev.c
Pablo Greco e6a3ae
@@ -130,6 +130,17 @@ sev_ram_block_added(RAMBlockNotifier *n, void *host, size_t size)
Pablo Greco e6a3ae
 {
Pablo Greco e6a3ae
     int r;
Pablo Greco e6a3ae
     struct kvm_enc_region range;
Pablo Greco e6a3ae
+    ram_addr_t offset;
Pablo Greco e6a3ae
+    MemoryRegion *mr;
Pablo Greco e6a3ae
+
Pablo Greco e6a3ae
+    /*
Pablo Greco e6a3ae
+     * The RAM device presents a memory region that should be treated
Pablo Greco e6a3ae
+     * as IO region and should not be pinned.
Pablo Greco e6a3ae
+     */
Pablo Greco e6a3ae
+    mr = memory_region_from_host(host, &offset);
Pablo Greco e6a3ae
+    if (mr && memory_region_is_ram_device(mr)) {
Pablo Greco e6a3ae
+	return;
Pablo Greco e6a3ae
+    }
Pablo Greco e6a3ae
 
Pablo Greco e6a3ae
     range.addr = (__u64)(unsigned long)host;
Pablo Greco e6a3ae
     range.size = size;
Pablo Greco e6a3ae
-- 
Pablo Greco e6a3ae
1.8.3.1
Pablo Greco e6a3ae